开发者

how to select all the data from many tables?

how to select all the data from many tables? i try

`"SELECT * FROM `table1`, `table2`"`

, but result none understandable for me. it returns only some rows from table1, and 3 times all the data from table2. i've red one same question here, but don't un开发者_运维技巧derstand the answer. so could you help me? thanks in advance.

update:

when i try

(SELECT * FROM `table1`) UNION (SELECT * FROM `table2`)

it returns #1222 - The used SELECT statements have a different number of columns


By doing that select with the "," between 2 tables and no WHERE clause, you are doing an implicit cross join of the 2 tables (all combinations of rows between the 2 tables). This is likely Not What You Want. See UNION, as mentioned by other answers.


Use the UNION SELECT construct


How do you want the data displayed? Are both tables of the same schema? If so you could use the UNION operator.

http://www.w3schools.com/sql/sql_union.asp


If you are just trying to show the data from many tables and there is no relationship between the data, you have to program logic instead of database logic.

show tables (SQL command)
foreach result (programming language of your choice)
select * from tablename (SQL command)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜