pietbez Posted January 6, 2009 Share Posted January 6, 2009 can any1 please tell me how to merge these 2 queries together? ("SELECT * FROM links WHERE item = $item and photourl IS NOT NULL" ); ("SELECT count(*) FROM `item_visits` WHERE item = $item " ); Link to comment https://forums.phpfreaks.com/topic/139753-2-tables-1query/ Share on other sites More sharing options...
revraz Posted January 6, 2009 Share Posted January 6, 2009 You really can't since they use different WHERE parameters. Link to comment https://forums.phpfreaks.com/topic/139753-2-tables-1query/#findComment-731168 Share on other sites More sharing options...
Mark Baker Posted January 6, 2009 Share Posted January 6, 2009 SELECT L.field1, L.field2, count(V.item) as visitCount FROM links L, item_visits V WHERE L.item = $item AND L.photourl IS NOT NULL AND V.item = L.item GROUP BY L.field1, L.field2 Link to comment https://forums.phpfreaks.com/topic/139753-2-tables-1query/#findComment-731209 Share on other sites More sharing options...
pietbez Posted January 7, 2009 Author Share Posted January 7, 2009 Like this? $do=mysql_query ("SELECT L.field1, L.field2, count(V.item) as visitCount FROM links L, item_visits V WHERE L.item = $item AND L.photourl IS NOT NULL AND V.item = L.item GROUP BY L.field1, L.field2" ); Link to comment https://forums.phpfreaks.com/topic/139753-2-tables-1query/#findComment-731248 Share on other sites More sharing options...
Mark Baker Posted January 7, 2009 Share Posted January 7, 2009 Like this? I'd guess I just provided the query, it's up to you to execute it however you'd normally execute your SQL statements from within PHP. But it's always worthwhile ensuring that the query itself works by executing it using phpmyadmin (or similar) before putting it in your code. Link to comment https://forums.phpfreaks.com/topic/139753-2-tables-1query/#findComment-731464 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.