Assuming the primary key is stored in a PHP variable, $key, then you can build your SQL query using double quotes:
$sql = "SELECT * FROM table1 WHERE ( SELECT COUNT(*) FROM table2 WHERE fbid = $key) > 150";
// run the query by passing $sql to your query handler
darkagn
Veteran Poster
1,197 posts since Aug 2007
Reputation Points: 404
Solved Threads: 200
What does your query do ? Query the table 'photos' and for every photo, You are again querying the table 'ratings' if that photo's fbid has a count > 150 ?
I didn't get the question or what you actually want. Do these 2 tables have any common 'linking' field ? What is fbid ?
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
select * from images where fbid IN (select fbid from ratings HAVING count(fbid) > 150 group by fbid)
The subquery returns fbid of all the records which has a count of 150+ . The main query returns all the records which matches these fbid.
Read more about having clause here.. http://www.techonthenet.com/sql/having.php
Not sure if this will work. If it doesn't, we ll try some other way :)
Cheers!
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
Hmm.. There was a little mistake in that query. Here, this works fine.
select * from images where fbid IN (
select fbid
from rating
group by fbid
HAVING count( fbid ) > 150
)
Cheers!
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356