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 [email protected] 2 1 Claudia Schiffer [email protected] 3 1 Jessica Alba [email protected] 4 2 Simon Emil Amitzbøll [email protected] 5 2 Mette Frederiksen [email protected] 6 3 bob Hansen [email protected] 7 3 Paul Gascoigne [email protected] 8 3 Paul Ince [email protected] 9 4 bob Hansen [email protected] 10 4 Paul Gascoigne [email protected] 11 4 Paul Ince [email protected] 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 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; Link to comment https://forums.phpfreaks.com/topic/216281-query-help/#findComment-1124103 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.