Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect syntax near the keyword 'Distinct'

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`     
like image 421
Ali Nouman Avatar asked Feb 05 '12 15:02

Ali Nouman


People also ask

Which of the following is the correct syntax of distinct keyword?

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.

What does DISTINCT do in sql?

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.

Can we use distinct keyword in where clause?

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.

Does DISTINCT apply to all Columns?

Yes, DISTINCT works on all combinations of column values for all columns in the SELECT clause.


1 Answers

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?

like image 152
Matti Virkkunen Avatar answered Sep 19 '22 16:09

Matti Virkkunen