moortje
moortje

Reputation: 45

MySQL error code 1064 when using distinct

I just began studying MySQL and ran into error 1064. It's a basic and short snippet. Please help, I've tried googling for about an hour now. I come to you as a last resort.

select  distinct(b.publisher), c.name
from  customer c, orders o, book b
where c.name = 'Park' and
c.custid = o.custid and b.bookid = o.bookid;

My question is that while above code works, if I put c.name in front of distinct(b.publisher), I get a 1064. Any help would be appreciated. Thank you!

Upvotes: 0

Views: 46

Answers (1)

Thomas G
Thomas G

Reputation: 10206

The purpose of DISTINCT is to eliminates doubles rows, meaning the exact same data in all your returned columns.

If you have several columns in your SELECT clause, you can NOT have DISTINCT on one column only. And this is the reason of your error 1064

Thus you should do either

select  distinct b.publisher, c.name

or

select  distinct b.publisher

which is the exact same as

select  distinct(b.publisher)

Upvotes: 1

Related Questions