Jump to content

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           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

 

Link to comment
https://forums.phpfreaks.com/topic/216281-query-help/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.