I want to select distinct values from only one column (the BoekingPlaatsId column) with this query:
SELECT MAX(BoekingPlaatsId), BewonerId, Naam, VoorNaam FROM table GROUP BY BewonerId, Naam, VoorNaam
How do I do that in SQL Server?
Adding the DISTINCT keyword to a SELECT query causes it to return only unique values for the specified column list so that duplicate rows are removed from the result set. Since DISTINCT operates on all of the fields in SELECT's column list, it can't be applied to an individual field that are part of a larger group.
To get unique or distinct values of a column in MySQL Table, use the following SQL Query. SELECT DISTINCT(column_name) FROM your_table_name; You can select distinct values for one or more columns. The column names has to be separated with comma.
Note – Use of IN for matching multiple values i.e. TOYOTA and HONDA in the same column i.e. COMPANY. Syntax: SELECT * FROM TABLE_NAME WHERE COLUMN_NAME IN (MATCHING_VALUE1,MATCHING_VALUE2);
Yes, DISTINCT works on all combinations of column values for all columns in the SELECT clause.
DISTINCT
should work if you just want the user names:
SELECT DISTINCT BewonerId, Naam, Voornaam FROM TBL
but if you need the minimum ID values, group by the names...
SELECT MIN(BoekingPlaatsId), MIN(BewonerId), Naam, Voornaam FROM TBL GROUP BY Naam, Voornaam
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With