
Originally Posted by
Rmazin
select cityName from cities where cityID = '1'
select userName, userEmail from users where userID = '53'
select jobName from jobs where jobID='2'
Is there a way to combine these into one query?
yup 
Code:
SELECT 'city' AS resulttype
, cityName AS result1
, NULL AS result2
FROM cities
WHERE cityID = 1
UNION ALL
SELECT 'user'
, userName
, userEmail
FROM users
WHERE userID = 53
UNION ALL
SELECT 'job'
, jobName
, NULL
FROM jobs
WHERE jobID = 2
p.s. please don't put quotes around numeric constants being compared to numeric columns
Bookmarks