[thelist] [mysql] join
Joshua Olson
joshua at waetech.com
Fri Jan 23 11:24:17 CST 2004
----- Original Message -----
From: "kris burford" <kris at midtempo.net>
Sent: Friday, January 23, 2004 12:13 PM
> $sql_one = "select id_one, id_two, some_other_stuff from table_one where
x";
> query
> fetch_rows
> $sql_two = "select name from table_two where id = id_one";
> $sql_three = "select name from table_two where id = id_two";
> is there any way that this can be done in a single request? could really
do
> without the extra overhead on the db...
Kris,
Yes, there is. You'll want to look at the UNION syntax (or UNION ALL if you
don't need duplicates removed):
SELECT table_two.name, some_other_stuff
FROM table_two
INNER JOIN table_one
ON table_one.id_one = table_two.id
WHERE [x]
UNION ALL
SELECT table_two.name, some_other_stuff
FROM table_two
INNER JOIN table_one
ON table_one.id_two = table_two.id
WHERE [x]
<><><><><><><><><><>
Joshua Olson
Web Application Engineer
WAE Tech Inc.
http://www.waetech.com/service_areas/
706.210.0168
More information about the thelist
mailing list