Hi
What SQL statement should i write if i want to select a data from a column that has duplicate data?
Any help or suggestion will be greatly appreciated
Printable View
Hi
What SQL statement should i write if i want to select a data from a column that has duplicate data?
Any help or suggestion will be greatly appreciated
I assume you only want the single occurence of the duplicates? just use DISTINCT. ie if you've a 'firstname' column (where you'll probably get multiple 'Steve's and 'Sarah's) you'd do:
Code:SELECT DISTINCT forename FROM names ORDER by forename
Thanks for the reply ANAKIM
But what should i do if that column contain duplicate numbers ?
Exactly the same! It matters not a jot what the column contains. Distinct can be used for multiple columns, say if you were looking for all the different results in an exam, if the table contained names and sexes of the entrants as well as the mark....
would get all the different scores while...Code:SELECT DISTINCT score FROM entrants
would get all the different scores for male, female and in-betweens.Code:SELECT DISTINCT score, sex FROM entrants