Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting unique elements

Status
Not open for further replies.

mawe

Programmer
Jun 22, 2000
2
SE
How can I alter the following SQL statement in order to get distinct OrderCodes but not distinct ProductNames:<br><br>SELECT OrderCode, ProductName FROM table<br><br>E.g &quot;111-1&quot; &quot;Red bike&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&quot;222-2&quot; &quot;Red bike&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&quot;333-3&quot; &quot;Red bike&quot;<br><br>Well, you get the general idea!<br><br>Thanks!
 
SELECT distinct OrderCode, ProductName FROM table <p>Ged Jones<br><a href=mailto:gedejones@hotmail.com>gedejones@hotmail.com</a><br><a href= > </a><br>
 
Sorry, my mistake! The SQL is something like this:<br><br>SELECT OrderCode, ProductName, para1, para2, para3 FROM table<br><br>Now, I want to make sure that every OrderCode is unique but the ProductName and the paras can be the same. E.g.<br><br>&quot;111-1&quot;, &quot;Red bike&quot;, 1, 1, 1<br>&quot;222-2&quot;, &quot;Red bike&quot;, 1, 1, 1<br>&quot;333-3&quot;, &quot;Red bike&quot;, 1, 1, 1<br><br>is valid, but<br><br>&quot;111-1&quot;, &quot;Red bike&quot;, 1, 1, 1<br>&quot;111-1&quot;, &quot;Red bike&quot;, 0, 0, 0<br><br>is not! <br><br>How can I change the SQL statement do make this possible?<br><br>Thanks!<br><br>
 
SELECT DISTINCT OrderCode, ProductName, para1, para2, para3 FROM table;<br>will give you a listing.&nbsp;&nbsp;However, if all you want to do is make sure that all of the OrderCode values are unique, you could try:<br><br>SELECT count(distinct OrderCode)/count(OrderCode) FROM table;<br><br>Any result less than 1 indicates non-unique values.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top