Jump to content

DISTINCT using two tables?


Mr Chris

Recommended Posts

Hi All,

 

I have two tables, a table called gallery, and a table called info

 

Now both have a field called gallery_id

 

Now in the gallery table the field gallery_id has lots of the same value ie: 5 so I want to get the DISTINT value, but the output displays the same value 5 in multiple rows.

 

SELECT DISTINCT i.info_id, g.gallery_id, g.main_name, i.opening, i.headline, DATE_FORMAT(i.published, '%W, %D %M, %Y') AS formatted_date, i.gallery_id
FROM gallery g, info i
WHERE g.gallery_id=i.gallery_id

 

Can anyone help?

 

Thanks

 

Chris

Link to comment
Share on other sites

  SELECT i.info_id, g.gallery_id, g.main_name, i.opening, i.headline, DATE_FORMAT(i.published, '%W, %D %M, %Y') AS formatted_date FROM gallery g
    INNER JOIN info i ON g.gallery_id = i.gallery_id
    GROUP BY g.gallery_id;

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.