I am getting following error in my query System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'Distinct'
. I have searched the Google but didn't find any helpful solution according to my query.My query is this
SqlCommand myCommand = new SqlCommand("select ItemId,Distinct Size from ItemTilesSizes ",
myConnection);
My table name is ItemTilesSizes
and it has two columns
ItemId Size
1 8x13
1 8x12
5 8x10
5 8x12
5 8x13
8 10x10
8 4x4
9 8x12
14 8x13
15 8x10
15 24x24`
Below is the syntax for a distinct keyword. Syntax: Select DISTINCT(expressions) from tables [where conditions]; Expressions: In this, we provide the column names or calculations that we want.
The SQL SELECT DISTINCT Statement The SELECT DISTINCT statement is used to return only distinct (different) values. Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.
By using the WHERE clause with a DISTINCT clause in MySQL queries, we are putting a condition on the basis of which MySQL returns the unique rows of the result set.
Yes, DISTINCT works on all combinations of column values for all columns in the SELECT clause.
DISTINCT
has to come first, but it'll get you all distinct pairs of ItemId
and Size
. Is that what you want or were you looking for something else?
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