Re: SQL help
| From: | Marc Greenstock | Date: | Wed, 11 Feb 2004 03:29:57 +0000 |
| Subject: | Re: SQL help | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-177344@lists.php.net to get a copy of this message | ||
That works well,
Thanks all.
"Warren Vail" <Warren.Vail@schwab.com> wrote in message
news:72138202E59CD6118E960002A52CD9D20F5D4650@n1025smx.nt.schwab.com...
> The problem is you are using a hard join which will only return rows where
> there are matching entries in both tables. What you probably want is
called
> a left join, however you have a further complication.
>
> You have to have an image row to have a image_data.Default_Img = 'Yes'.
So
> this query is really designed to only return users who have default images
> established (other images don't count either).
>
> Haven't tested this, but it reflects my understanding of your expectation
> (haven't double checked syntax either, but you can at
> http://www.mysql.com/doc/en/index.html);
>
> SELECT * FROM user_data
> left join image_data
> on user_data.User_ID = image_data.User_ID
> where image_data.Default_Img in ('Yes', '')
> GROUP BY user_data.User_ID
>
> hope this works for you, good luck,
>
> Warren Vail
>
>
> -----Original Message-----
> From: Marc Greenstock [mailto:marc@shockmedia.com.au]
> Sent: Tuesday, February 10, 2004 6:53 PM
> To: php-general@lists.php.net
> Subject: [PHP] SQL help
>
>
> Hi all here's my problem,
>
> I have two tables: 'user_data' and 'image_data'
>
> obviously user_data has all the user information and image_data has all
the
> image information
>
> in image_data are the fields: Image_ID int(11), User_ID int(11) and
> Default_Img enum('Yes','No'). Users can have as many images as they like,
> but it is optional.
>
> I want to select from user_data and image_data and get the results based
> upon the rest of the query. The problem is my sql is only pulling out the
> users with images and ignoring the rest
>
> my sql looks like this:
>
> SELECT * FROM user_data, image_data
> WHERE user_data.User_ID = image_data.User_ID
> AND image_data.Default_Img = 'Yes'
> GROUP BY user_data.User_ID
>
> thanks for your help.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php