Reputation: 1257
Have two mysql tables such as
Table1
Id
Field1
Field2
Table2
Id
LinkId
Field3
Field4
The common fields to link the tables are Table1.Id
and Table2.LinkId.
Also important tha Table2 can have multiple rows where LinkId are the same.
So what I have been trying to figure is a mysql query to Select all rows in Table1 that have a linked row or more in Table2 where Field3 contains a certain value. Is this easily possible?
Upvotes: 0
Views: 88
Reputation: 32148
You can have multiple tables in the FROM
clause:
SELECT *
FROM Table1, Table2
WHERE Table2.Field3 = 'certain value'
AND Table1.Id = Table2.LinkId
Upvotes: 0
Reputation: 28403
Simply use JOIN
SELECT Table1.*
FROM Table1 A JOIN Table2 B ON A.Id = B.LinkID
WHERE B.Field3 IN ('Your inputs')
Upvotes: 1