Select distinct values from 1 column

后端 未结 9 2101
忘了有多久
忘了有多久 2020-12-10 00:47

I want to select distinct values from only one column (the BoekingPlaatsId column) with this query:

SELECT MAX(BoekingPlaatsId), BewonerId, Naam, VoorNaam
F         


        
9条回答
  •  执念已碎
    2020-12-10 01:34

    I think you should be able to use

    SELECT DISTINCT BewonerId, Naam, VoorNaam
    

    You can't add BoekingPlaatsId, because:

    • DISTINCT looks for unique rows
    • You need to specify what BoekingPlaatsId value you want
      (In case of Jan Janssens, do you want BoekingPlaatsId 1 or 2?)

    What also works is this:

    SELECT MAX(BoekingPlaatsId), BewonerId, Naam, VoorNaam
    FROM ...
    GROUP BY BewonerId, Naam, VoorNaam
    

提交回复
热议问题