php - Can I use a subquery's result as well? -


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 | approved | |  4 |    2 | pending  | |  5 |    3 | rejected | +----+------+----------+ 

id (from ads) = adid (from requests).

i have query:

select * ads id in (select adid requests status = 'approved' or status = 'rejected') 

this gives me rows ids 1 , 3 ads. question is, can use 'approved' or 'rejected' subquery well?

so there way can say:

$sql="select * ads id in (select adid requests status = 'approved' or status = 'rejected')"; $result=mysqli_query($con, $sql); while($row = mysqli_fetch_assoc($result)) {     echo $row['status']; //<--- doesn't work right now. want 'approved'/'rejected' }  

and works?

a where ... in query filter. can same filtering join:

select  *     ads join    requests r on      a.id = r.adid   r.status in ('approved', 'rejected') 

unlike where ... in filter, inner join filter includes columns other table in result.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -