Originally posted by TOrpheus
Hi,
Scenario: I have 2 tables that do not have a common key, but they both have lastname as a field.
How do I join these 2 tables and SORT by the lastname field?
Thanks!
You original question was how to join the 2 tables and then sort, which isn't what you want - you want to merge the data.
if you had mySQL 4 you do this
SELECT lastname from t1
UNION
SELECT lastname from t2
ORDER BY lastname
However, as v3 doesn't support unions you can do it by creating a temp table and appending to it. Then selecting and sorting.
CREATE table temp (lastname varchar(30))
INSERT INTO temp SELECT lastname FROM t1
INSERT INTO temp SELECT lastname FROM t2
SELECT lastname FROM temp ORDER BY lastname
hth