Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can mysql join 2 queries into 1 record set?

Status
Not open for further replies.

justride

Programmer
Jan 9, 2004
251
US
May be a silly question, but if I cannot make a query work can i combine the results of 2 different queries into 1 record set?

can we combine records from :

SELECT RESTNAME AS SET1 FROM RESTAURANTS WHERE RESTCITY = '$city'

SELECT RESTNAME AS SET2 FROM RESTAURANTS WHERE RESTZIP = '$zip'

I know this is an easy example and we can combine them in 1 query, but for complicated purposes is there a way to combine both sets and sort the full set ....

somthing like JOIN SET1 ON SET2 ???
 
that might be a bad example, i want the final record set to keep the field name as restname.
 
You mean you want the final result set to contain the records from both queries?

To do that, you can use UNION ALL:
[tt]
SELECT fld1,fld2 FROM tbl1 WHERE fld3='abc'
UNION ALL
SELECT fld3,0 FROM tbl2
ORDER BY fld1
[/tt]
Both queries must return the same number of fields. The fields in the final result set take their names from those in the first query, in this case 'fld1' and 'fld2', and the sorting is applied to the final result set.
 
hmmm, this may work, I will give it a shot! thansk so much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top