Possible Duplicate:
What is the difference between Join and Union?
How do we combine separate queries into single sql statement? example:
SELECT packageid FROM tblhosting WHERE id='$id' AND userid='$userid'
SELECT id FROM tblcustomfields WHERE relid=tblhosting.packageid AND fieldname='foo'
SELECT value FROM tblcustomfieldsvalues WHERE fieldid=tblcustomfields.id AND relid='$id'
Now, I am aware of nested queryes, so I could write this like this:
but I was wondering if there is a better way to write this query?
[Update2] here is a version without variables, hope its more clear this time
SELECT packageid FROM tblhosting WHERE id='$id' AND userid='$userid'
SELECT id FROM tblcustomfields WHERE relid=tblhosting.packageid AND fieldname='foo'
SELECT value FROM tblcustomfieldsvalues WHERE fieldid=tblcustomfields.id AND relid='$id'
here I only interested in tblcustomfieldvalues.value