I seem to be having a problem with my SQL query that’s driving me mad. I just can’t seem to get the group by to work. I keep getting the following error:
00979. 00000 - "not a GROUP BY expression"
My query:
SELECT customers.customer_first_name, customers.customer_last_name, orders.customer_numb, books.author_name, books.title
FROM customers
LEFT OUTER JOIN orders ON (orders.customer_numb = customers.customer_numb)
LEFT OUTER JOIN order_lines ON (order_lines.order_numb = orders.order_numb)
LEFT OUTER JOIN books ON (books.isbn = order_lines.isbn)
WHERE (customers.customer_numb = 6)
GROUP BY (books.title)
Database schema:
Customers:

Order Lines & Orders:

What I’m trying to achieve:
I’m trying to group by book titles so that it doesn’t show duplicate titles.
I apologise if I’ve missed anything, thanks.
What don’t you understand? Your select statement contains many columns that are not in the
group byclause. Try this:Since you are not aggregating anything, you can dispense with the
group by, and just usedistinctin theselectclause: