tags:

views:

54

answers:

3

I have two tables each with a field we will call widgetid.

I need to run a query on both tables, that will return a single list of widgetid's from both tables.

I have no idea how to do this.

What i have now is:

        $result = mysql_query("SELECT * FROM `inventory` WHERE find_in_set('$serial', items)") or die(mysql_error());
        while($row = mysql_fetch_array($result)){ 
        foreach($row AS $key => $value) { $row[$key] = stripslashes($value); } 
        $widgetid = $row['widgetid'];

        //Do Stuff For Each WidgetID

        }

Now i need to take that same $serial, and search the second table for its list of widgetid's. But i need to still be able to "do stuff" in the same place, with both lists of widgetids as one

+5  A: 
SELECT widgetid FROM TABLE1 WHERE find_in_set('$serial', items)
UNION
SELECT widgetid FROM TABLE2 WHERE find_in_set('$serial', items)

Is that what you are looking for? This will combine two select querys and give you it as a single result.

Chacha102
+3  A: 

I think you're looking for a UNION.

munch
+2  A: 

Why don't you use a union

Select widgetid from table1   
UNION
select widgetid from table2
RHicke