I have a table named Group in my database , when I try to work on it it gave error :
SELECT GroupID,GroupName FROM Group
it said :
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'Group'.
I know that Group is illegal name for table but its a old database with too many data and relations , and I cant rename this table , is there any way to work with table ?
Syntax: SELECT column1, function_name(column2) FROM table_name WHERE condition GROUP BY column1, column2 ORDER BY column1, column2; function_name: Name of the function used for example, SUM() , AVG(). table_name: Name of the table. condition: Condition used.
The SQL GROUP BY clause is used in collaboration with the SELECT statement to arrange identical data into groups. This GROUP BY clause follows the WHERE clause in a SELECT statement and precedes the ORDER BY clause.
The GROUP BY clause is used along with some aggregate functions to group columns with the same values in different rows. The group by multiple columns technique retrieves grouped column values from one or more database tables by considering more than one column as grouping criteria.
SQL COUNT( ) with group by and order byThe GROUP BY makes the result set in summary rows by the value of one or more columns. Each same value on the specific column will be treated as an individual group.
You can use Square Brackets [
and ]
in the Column name,Table Name.
SELECT GroupID,GroupName FROM [Group]
other eg.
select * from [table]
select [primary] from [table]
P.S: it worked by adding [dbo] before [Group] , so it is now like :
SELECT GroupID, GroupName FROM [dbo].[Group]
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