2

Starting to learn SQL, right now I'm using mysql to start off. Currently stuck on one problem on my SQL homework in which I have to:

Show all genres in which there is at least one title. List each genre only once.

Tried using command line:

SELECT DISTINCT Genre, Title, FROM Titles;

Does not give me my desired result.

enter image description here

Can anyone please show me, what I'm doing wrong here?

2
  • Please post the schema of the tables you're using. Commented Apr 13, 2015 at 6:20
  • distinct is same for mysql and oracle: Read this techonthenet.com/oracle/distinct.php Commented Apr 13, 2015 at 7:01

4 Answers 4

2

your task is to show genres, why do you need title in query?

SELECT DISTINCT Genre FROM Titles;
Sign up to request clarification or add additional context in comments.

1 Comment

@RahulTripathi yes, if this genre in titles table - it has at least one title already
0

You can try like this:

SELECT * FROM Titles where Titles is not null
group by Genre 

Comments

0

Use GROUP BY

SELECT Genre, Title FROM Titles WHERE Title <> '' GROUP BY Genre;

See example SQL Fiddle.

Comments

0

you use comma after Tilte that is wrong syntax.

This wright way is

SELECT Genre, Title FROM Titles WHERE Title IS NOT NULL GROPU BY Genre;

Comments

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.