I am trying to sort data by using the GROUP BY function. My query works fine until I add this to it. Here it is:
SELECT a.cust_id, a.account_id, a.product_cd, status, b.name, i.fname, i.lname,
from account a, branch b, individual i
where b.name = 'So. NH Branch' or b.name = 'Woburn Branch' and a.status = 'ACTIVE'
group by b.name;
I get this message: 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 ‘from account a, branch b, individual i
where b.name = ‘So. NH Branch’ or b.name ‘ at line 2
You have an extra comma in your
SELECT:One thing that I do see that is strange with your query is you are not joining your tables, you are returning a cartesian result set.
If you do not want a cartesian result set, then you would use a
JOINbetween the tables. Similar to this:Note: I guessed on the column names that would join the tables.