I have 2 tables:
Ads: Fields ID
, A
, B
and C
:
+----+---+-------+------+
| ID | A | B | C |
+----+---+-------+------+
| 1 | x | y | z |
| 2 | c | v | b |
| 3 | n | n | m |
+----+---+-------+------+
Requests: Fields ID
, AdID
, and Status
:
+----+------+----------+
| ID | AdID | Status |
+----+------+----------+
| 3 | 1 | pending |
| 4 | 2 | approved |
| 5 | 3 | pending |
+----+------+----------+
ID
(from Ads
) = AdID
(from Requests
).
Now, I want to get all records from Ads
where AdID
's (from Requests
) Status
equals pending
. AdId
here would be the value ID
from Ads
.
So, with the above tables, the result I'd get would be ID 1 and 3 from Ads:
+----+---+---+---+
| ID | A | B | C |
+----+---+---+---+
| 1 | x | y | z |
| 3 | n | n | m |
+----+---+---+---+
This is the closest I've got so far, but this obviously doesn't work because it can only select one row - whereas I need to select many:
SELECT * FROM Ads WHERE ID = (SELECT AdID FROM Requests WHERE Status = 'pending')
This might not make sense - please ask if I haven't explained it well - I'll help as much as possible :)
Use IN
in place of =
:
SELECT *
FROM Ads
WHERE ID IN (SELECT AdID FROM Requests WHERE Status = 'pending')
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments