James Stafford
James Stafford

Reputation: 1054

Select all rows which column has not already returned existing result

I am trying to pull records up from a mysql database but I want the result in one column to be completely unique

below is an example table

fname  | lname  | Street
-----------------------
john   | brown  | camelot st
george | kent   | camelot st
fred   | kent   | johnston rd
jane   |williams| camelot st
jack   | johnson| archer dr
james  | smith  | bruce st
adam   | smith  | james dr

below is the results I would want

Street
-----------
camelot st
johnston rd
archer dr
bruce st
james dr

in other words the first time any street name is returned it should display in the results after the first time it is no longer unique in the result and it should be omitted.

How would I manage this in mysql

Upvotes: 0

Views: 32

Answers (1)

Wolfie
Wolfie

Reputation: 1381

SELECT * FROM tableName 
WHERE street IN (
    SELECT DISTINCT street FROM tableName
) LIMIT 1;

This query should answer your question. However, it is important to note that you should order by an id field, because otherwise there is no guarantee that the rows in your database will always be queried in the same order.

Upvotes: 2

Related Questions