distinct queries

SELECT DISTINCT (First_Name ), distinct (last_name) FROM  CHECKED_OUT WHERE  Book_ID  not null


why above query not working
can i put one distinct for both first name and last name
are these queries case sensitive like unix?

please advise on any good links and resources, videos around this to master
LVL 7
gudii9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
Need to fix few syntax issues..

1. DISTINCT keyword is for the entire SET and it has to be specified only once for all columns in SELECT clause unless you have any Aggregate functions available.
2. In the WHERE clause it should be IS NOT NULL instead of just NOT NULL
corrected code below..
SELECT DISTINCT First_Name, last_name FROM CHECKED_OUT WHERE Book_ID IS not null

Open in new window

Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
Wondering whether this is any assignment or something, kindly confirm..
PortletPaulEE Topic AdvisorCommented:
@Raja Jegan R
gudii9 appears to be undertaking a crash course in SQL, there was a flurry of similar questions earlier also asking for learning guides/places to learn/places to trial things
 =========

SELECT DISTINCT (First_Name ), distinct (last_name) FROM  CHECKED_OUT WHERE  Book_ID  not null

why above query not working because  you need   IS not null (you were missing the IS )

can i put one distinct for both first name and last name NO
In fact "select distinct" makes THE WHOLE ROW "distinct"
i.e. it compares each row to all other rows and only if a row has some difference will it remain in the result

SELECT DISTINCT First_Name, last_name FROM  CHECKED_OUT WHERE  Book_ID IS NOT NULL

PLEASE remember that the word distinct belongs to the select here, as in SELECT DISTINCT
and that, distinct IS NOT a function so it does NOT take the column name/s as a parameter

are these queries case sensitive like unix?
NO for SQL, but literals might be case sensitive

e.g.
select distinct = SELECT DISTINCT = SeLecT dIStinCT = Select Distinct

but

where column1 = 'ThisMightBeCaseSensitive'  


So, to answer this simply really isn't possible. Again "which database"  absolutely matters here.  e.g.
Oracle data is usually case sensitive, but not always
SQL Server data is usually case insensitive, but not always

So. SQL commands are NOT case sensitive but DATA can be
PortletPaulEE Topic AdvisorCommented:
2 tips

1. Choose A database to learn SQL with.
Stick to that database until you believe you can try something else.
This will allow you to buy books suited to the database you are learning

It will also help us to help you by providing the syntax for that database.
(if you list the correct topic with your question.


2. Depending on which database you choose
http://poorsql.com/ this site will help you format your queries,  and it might detect errors for you, but this is not always true. This site is "generic" and it doesn't matter too much which database is used.

https://sql-format.com/ this site is specifically for SQL Server SQL (called "T-SQL") and it is much more accurate in finding errors. But this is much less relevant for any other databases.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.