Take the 2-minute tour ×

I want to get one value out of 5 which are the same, lets say 5 records have the same value in some column.

How do I only get one out of them and not 5 ?

share|improve this question
add comment

4 Answers

up vote 6 down vote accepted

Add DISTINCT to your query:

share|improve this answer
What if you wanna use what? Sorry, didn't get your question. –  favoretti Aug 11 '12 at 23:30
was asking how to select * and not a field, i figured its SELECT DISTINCT *, am i right ? –  Osa Aug 11 '12 at 23:30
Yes, it's correct, although I'm not sure you'll get desirable results :) –  favoretti Aug 11 '12 at 23:32
i don't get it, could u provide a short explanation of DISTINCT ? and how to get SELECT * in it? –  Osa Aug 11 '12 at 23:32
If you can elaborate your goal, I can help you better. You want to select each field of the table, only unique values of each? –  favoretti Aug 11 '12 at 23:34
show 3 more comments

You can group them using MySQl's GROUP BY function.

SELECT field FROM table GROUP BY field
share|improve this answer
add comment

You could use

"SELECT * WHERE column = 'Term' ORDER BY column2 LIMIT 1"

and then a simple while loop to output the data

share|improve this answer
Sorry mate, but this is a VERY weird approach to the task :) –  favoretti Aug 11 '12 at 23:36
add comment

Sample query

BookId, BookName, BookCategory,
COUNT( BookReferenceNumber ) AS HowManyRecs,
BookDetails, BookStatus


BookReferenceNumber LIKE '42324%'
OR BookName LIKE '%42324%'
BookStatus = 'Available'
GROUP BY BookReferenceNumber
HowManyRecs > 0

Here it is explained with an example


share|improve this answer
add comment

Your Answer


