views:

42

answers:

3

If i have tables such as:

table_1: 1, 'Hello My Name is Hal', '2009:11:02 08:42'
table_1: 2, 'Hello My Name is Dave', '2009:11:02 08:30'
table_2: 1, 'Ima all #red due to twitter', '2009:11:02 09:42'

And lets imagine all the table columns have the same col_names

Is there any way i can do a query to return the results in one SELECT on different Rows

Something Along the lines of:

SELECT * FROM table_1, table_2 ORDER BY dateReg DESC

So my Return will look like:

1, 'Ima all #red due to twitter', '2009:11:02 09:42'
1, 'Hello My Name is Hal', '2009:11:02 08:42'
2, 'Hello My Name is Dave', '2009:11:02 08:30'

When I try to run the above query I get Ambiguity Errors (Obviously...Duhh..:D) but is there a way we can do that in query rather than sorting in code using PHP.

Any Ideas? Thanks in advance

A: 

Use table aliasas ;)

Something like:

SELECT table1.id AS table1_id, table2.id AS table2_id, table3.id AS table3_id FROM table1, table2, table3

Ben Fransen
This is a cross-join, which is not what the question is about.
Lukáš Lalinský
+2  A: 

You can use UNION (or UNION ALL) to combine results from multiple queries:

SELECT * FROM table_1 UNION ALL SELECT * FROM table_2

(Simple UNION will remove duplicates, UNION ALL will return all results.)

Lukáš Lalinský
ty genious.......15 chars
Shahmir Javaid
+1  A: 

You can use UNION Queries

astander