baudits Posted October 19, 2010 Share Posted October 19, 2010 Help making a query. I have these 2 tabels. I have to make a query that shows: partydate header partyid and number of guest to that party like this: partydate header partyid guests 2010-11-08 Årets Fest 1 3 2010-11-15 Øl Fest 4 3 2010-12-04 Fodbold Fest 3 3 2010-12-06 Politik Fest 2 2 Tabel 1) partyID header body partydate 1 Årets Fest Det her er bare.... 2010-11-08 2 Politik Fest Fest for alle som... 2010-12-06 3 Fodbold Fest Fest for alle som... 2010-12-04 4 Øl Fest Fest for alle som... 2010-11-15 Tabel 2) guestsid partyid name email 1 1 bob Hansen bgga@bob.dk 2 1 Claudia Schiffer genau@hotmail.com 3 1 Jessica Alba veryhotgirl@hotmail.com 4 2 Simon Emil Amitzbøll sea@hna.dk 5 2 Mette Frederiksen mette@social.dk 6 3 bob Hansen bgga@bob.dk 7 3 Paul Gascoigne gazza@drinksalot.com 8 3 Paul Ince ince@hotmail.com 9 4 bob Hansen bgga@bob.dk 10 4 Paul Gascoigne gazza@drinksalot.com 11 4 Paul Ince ince@hotmail.com I tried whit this it shows want i want except the number of guests. SELECT DISTINCT partydate, header, parties.partyid, body FROM dsds.parties LEFT JOIN dsds.guests ON parties.partyid = guests.partyid WHERE partydate >= NOW() ORDER BY partydate; it shows: partydate header partyid body 2010-11-08 Årets Fest 1 Det her er bare... 2010-11-15 Øl Fest 4 Fest for alle som... 2010-12-04 Fodbold Fest 3 Fest for alle som... 2010-12-06 Lesbisk Fest 2 Fest for alle som... then i tried with this: SELECT DISTINCT partydate, header, parties.partyid, body, COUNT(guests.guestsid) AS 'No guests' FROM dsds.parties LEFT JOIN dsds.guests ON parties.partyid = guests.partyid WHERE partydate >= NOW() ORDER BY partydate; only shows: partydate header partyid body No guests 2010-11-08 Årets Fest 1 Det her er bare... 11 Can anyone help me? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/216281-query-help/ Share on other sites More sharing options...
baudits Posted October 19, 2010 Author Share Posted October 19, 2010 I got this query to answer my question. SELECT partydate, header, parties.partyid, COUNT(*) AS guests FROM dsds.parties JOIN dsds.guests on parties.partyid = guests.partyid GROUP BY partydate, header, partyid; Quote Link to comment https://forums.phpfreaks.com/topic/216281-query-help/#findComment-1124103 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.