Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to work with Sql table named Group

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 ?

like image 672
arash rajaei Avatar asked Oct 30 '14 08:10

arash rajaei


People also ask

How do I run a SQL GROUP BY?

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.

Can we use where with GROUP BY in SQL?

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.

How does GROUP BY work with multiple columns in SQL?

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.

How does count work with GROUP BY?

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.


1 Answers

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]
like image 122
Ganesh Avatar answered Sep 27 '22 20:09

Ganesh