[thelist] mysql question

Simon Lee simon.lee at leapforward.net
Wed Oct 16 12:40:00 CDT 2002


> Hello,
>
> I have a certain search that I need to perform that searches
> for items in multiple tables. How would I combine the following query
>
> select item_id from tableA WHERE item_review='$search_term';
>
> select item_id from tableB WHERE description='$search_term';
>
> Can these be combined to return results from both tables?
>
Yes and No Kevin.

The following SQL string would work...

$sql = "
	select item_id from tableA WHERE item_review='$search_term'
	UNION
	select item_id from tableB WHERE description='$search_term'
";

BUT...one of the many 'features' of MySQL is that it doesn't support the
UNION construct, so you'll have to create a temporary table to return
the results, or run separate queries.....or use another db e.g.
PostgreSQL, Oracle, etc.

HTH
sl




More information about the thelist mailing list