views:

47

answers:

4

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 understand 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

+1  A: 

Use the UNION SELECT construct

Simone Margaritelli
+1  A: 

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

Raj Kaimal
+2  A: 

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.

David Gelhar
A: 

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)

Elizabeth Buckwalter