SQL – ‘DISTINCT’ based on only some columns?

You probably need to use GROUP BY instead of DISTINCT in this case.

Post your query now and I will help you more.

Alternatively, if you just want to return the first address, that’s a different query entirely. Does it need to return the address? What data do you need? What does “first” mean in this context? How is the data ordered?

Arbitrarily you could do something like this (untested), depending on your DB:

SELECT 
    userID
    , FIRST(address)
FROM
    yourTable
GROUP BY
    userID

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)