Hello, I have the following tables:
CREATE TABLE movies (movies,name);
CREATE TABLE genres (movies,genres);

Every movie has many genres and every genre has many movies.
I want to list all genres but those who match a specified movie must be
marked.

For example for movie "tt1637725":
SELECT distinct genres,movies from genres WHERE movies='tt1637725'
UNION ALL
SELECT distinct genres,'' FROM genres WHERE genres NOT IN (SELECT distinct
genres FROM genres WHERE movies='tt1637725') group by genres order by
genres;

Action|
Adult|
Adventure|
Animation|
Biography|
Comedy|tt1637725
Crime|
Documentary|
Drama|
Family|
Fantasy|tt1637725
Film-Noir|
History|
Horror|
Music|
Musical|
Mystery|
Romance|
Sci-Fi|
Short|
Sport|
Thriller|
War|
Western|

Is there any way to improve that code?
Thanks in advance!



--
View this message in context: 
http://sqlite.1065341.n5.nabble.com/How-can-I-improve-this-query-tp67470.html
Sent from the SQLite mailing list archive at Nabble.com.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to