php - Select all fields from a table where a field in another table with an ID is equal to a string -
i have 2 tables:
ads: fields id, a, b , c:
+----+---+-------+------+ | id | | b | c | +----+---+-------+------+ | 1 | x | y | z | | 2 | c | v | b | | 3 | n | n | m | +----+---+-------+------+ requests: fields id, adid, , status:
+----+------+----------+ | id | adid | status | +----+------+----------+ | 3 | 1 | pending | | 4 | 2 | approved | | 5 | 3 | pending | +----+------+----------+ id (from ads) = adid (from requests).
now, want records ads adid's (from requests) status equals pending. adid here the value id ads.
so, above tables, result i'd id 1 , 3 ads:
+----+---+---+---+ | id | | b | c | +----+---+---+---+ | 1 | x | y | z | | 3 | n | n | m | +----+---+---+---+ this closest i've got far, doesn't work because can select 1 row - whereas need select many:
select * ads id = (select adid requests status = 'pending') this might not make sense - please ask if haven't explained - i'll as possible :)
use in in place of =:
select * ads id in (select adid requests status = 'pending')
Comments
Post a Comment