jake2891 Posted March 27, 2009 Share Posted March 27, 2009 Hi Guys, just a small table example of what im trying to do sale_id buyer_id 1 2 1 2 1 4 2 3 3 5 Im trying to get all the data out of the table where the sale_id has more than 1 buyer_id so basically im trying to just get the first 2 records back i though it would be something like the following select * from sale where (select count(buyer_id) > 1) // so where the sale_id has more than 1 buyer_id on it but this does not work any help please Quote Link to comment https://forums.phpfreaks.com/topic/151406-solved-sql-query-help/ Share on other sites More sharing options...
Maq Posted March 27, 2009 Share Posted March 27, 2009 SELECT sale_id, buyer_id, COUNT(buyer_id) AS count FROM table GROUP BY sale_id HAVING count > 1; Quote Link to comment https://forums.phpfreaks.com/topic/151406-solved-sql-query-help/#findComment-795256 Share on other sites More sharing options...
jake2891 Posted March 27, 2009 Author Share Posted March 27, 2009 SELECT sale_id, buyer_id, COUNT(buyer_id) AS count FROM table GROUP BY sale_id HAVING count > 1; thanks for that Quote Link to comment https://forums.phpfreaks.com/topic/151406-solved-sql-query-help/#findComment-795265 Share on other sites More sharing options...
Maq Posted March 27, 2009 Share Posted March 27, 2009 Sure, if I understood your question correctly it should work. I'm a little confused about this: Im trying to get all the data out of the table where the sale_id has more than 1 buyer_id so basically im trying to just get the first 2 records back Only sale_id 1 has more than 1 buyer, so why would you expect 2 records back? Quote Link to comment https://forums.phpfreaks.com/topic/151406-solved-sql-query-help/#findComment-795266 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.