query from 3 tables in 1
I am trying to query specific information from 3 tables, the only relationship in the data is that it was selected from the same form.
here is my table info
columns: cityID, cityName, cityState
columns: userID, userName, userEmail
columns: jobID, jobName, jobStart
Individually the queries would be:
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?
I will be displaying the results back using PHP.
Afaik (and I'm no expert) but those are then three different queries, you can't do a join if there is no relationship between the tables and you can't select data from three different tables without a join
But it appears you could very well establish a relationship between them, for example the job table could get a field cityID to identify the city the job is located.
More info on joins: http://www.w3schools.com/sql/sql_join.asp
Originally Posted by Rmazin
p.s. please don't put quotes around numeric constants being compared to numeric columns
SELECT 'city' AS resulttype
, cityName AS result1
, NULL AS result2
WHERE cityID = 1
WHERE userID = 53
WHERE jobID = 2