I have a database that which contains two tables, links and tour. Tour is defined as
+----+-------------+-----+-----+--------+---------+-------+---------+
| ID | FileName | Lat | Lon | Name | Heading | Width | Height |
+----+-------------+-----+-----+--------+---------+-------+---------+
and links is defined as
+-----+------------+--------+
| ID | locationID | linkID |
+-----+------------+--------+
links.locationID is a foreign key to tour.ID. What I want to do is grab all the links that match to a specific tour.name
Right now, I have to run these two queries and use the ID of the first as a variable for the second
SELECT * FROM tour WHERE tour.name = 'name'
SELECT * FROM tour
INNER JOIN links ON tour.ID = links.linkID
WHERE links.locationID = ID of first query
How can I adapt this to a single search?
I’ve tried a subquery:
SELECT * FROM tour
INNER JOIN links ON tour.ID = links.linkID
WHERE links.locationID = ( SELECT * FROM tour WHERE tour.name = 'name')
This gives me an error 1241 saying that operand should contain one column.
I’ve looked up some examples of subqueries, but hey all lack the inner join statement I’m using. What modifications are necessary to this query?
As for your version with subquery, you could do:
But prefer the first option.