不同的SQL联接 JOIN:位于时返回行两个表中至少有一个匹配项左联接:从中返回所有行左桌子,即使没有右表中的匹配项 RIGHT JOIN:从中返回所有行正确的桌子,即使没有左侧表格中的匹配项完全联接:存在时返回行一张桌子中的一个匹配项How can I select the contents of two columns that reside in different tables in a mysql database? 解决方案 You would need to use either a JOIN or UNION/UNION ALL.This will depend on wht you require.Lets say you want all values from table 1 col a and table 2 col b in seperate rowsYou can useSELECT ColAFROM TABLE1UNION ALLSELECT ColBFROM TABLE2All Distinct ValuesSELECT ColAFROM TABLE1UNIONSELECT ColBFROM TABLE2And lets say that the you want to display them in the same row, they should have some key that links themSELECT ColA, ColBFROM TABLE1 t1 INNER JOIN TABLE2 t2 ON t1.ID = t2.IDIt would also be good to note that there are different types of Sql JoinsDifferent SQL JOINsJOIN: Return rows when there is atleast one match in both tablesLEFT JOIN: Return all rows from theleft table, even if there are nomatches in the right tableRIGHT JOIN: Return all rows from theright table, even if there are nomatches in the left tableFULL JOIN: Return rows when there isa match in one of the tables 这篇关于如何从Mysql中两个不同的表中选择内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-02 18:13