|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Query - General - Returning duplicate records
Hi,
I have a MySQL database where I store records for images in one table and photographers details in another. When an image is added to the images table it is linked to a photographer using the photographers ID. The images are also split up into different categories. What I want to do is compile a list of all photographers who have images in a specified category. See below the SQL I have come up with. Code:
SELECT p.ID, p.name FROM photographers p, images i WHERE p.ID = i.photographerID AND i.category = 5 ORDER BY p.ID ASC The SQL above returns the photographers that have images within that category, which is what I want, but the problem is if the photographer 'Joe Bloggs' has 50 images within category 5, it will return his name 50 times, and I only need it to be returned once. I understand why it's doing this, I just can't work out the correct SQL to return the photographers names only once. Can anyone help? |
|
#2
|
|||
|
|||
|
Use the DISTINCT condition in the SQL
Code:
SELECT DISTINCT p.ID, p.name FROM photographers p, images i WHERE p.ID = i.photographerID AND i.category = 5 ORDER BY p.ID ASC |
|
#3
|
|||
|
|||
|
or use row_number() function
|
|
#4
|
|||
|
|||
|
Re: Returning duplicate records
Hi, I hope the below query will be useful for you.
Quote:
Thanks & Regards Sakthimeenakshi.S |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Query - General - Returning duplicate records |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|