Jump to content

query help


baudits

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.