Jump to content

Simple DB join


johnsmith153

Recommended Posts

Joining two tables:

 

A simple users and photos table. They are connected by a user_id field.

 

(1) Users table.

 

(2) Photos (a 'profile_pic' field flags which photo is the profile picture)

 

There are lots of records in the photos table.

 

I want to simply return every user and display their profile picture (if they have one).

 

These are the issues I have:

 

(1) A simple join always returns the same number of records as there are photos, not one record per user (so if a user has 50 photos, I see the user record 50 times).

 

(2) If I use GROUP BY then I don;t see multiple records per user, but I don;t have any control over which record is selected from the Photos table.

 

(3) If I simply use:

 

WHERE profile_pic = '1'

 

...then if someone doesn;t have a profile pic I don;t see their record at all.

Link to comment
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.