2

I have two MySQL tables: Group(gr_id, gr_name, gr_description, parent_id) Group_has_User(User_id, Group_id)

I'm trying to execute the query:

SELECT group.gr_id, group.gr_name, group.gr_description, group.parent_id 
FROM group, Group_has_User AS gu
WHERE (group.gr_id = gu.Group_id) AND gu.User_id = 1

It gives an error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group, Group_has_User AS gu WHERE (group.gr_id = gu.Group_id) AND gu.User_id = 1' at line 1

How should I write it correct?

4 Answers 4

4

group is a keyword in SQL. Enclose such names in backticks

FROM `group`, Group_has_User AS gu
Sign up to request clarification or add additional context in comments.

Comments

2

group is a keyword in SQL. Try giving your tables more sensible names, or using:

SELECT g.gr_id, g.gr_name, g.gr_description, g.parent_id 
    FROM `group` g, Group_has_User AS gu
    WHERE (g.gr_id = gu.Group_id) AND gu.User_id = 1

Comments

-1

Try this. Remove the "AS" keyword after the table name Group_has_User and execute the query

Comments

-2

Maybe you must write 'Group', not 'group'.

1 Comment

In that case there will be different error message. Don't you read?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.