sql - MySQL proper way to SELECT with many tables involved -


i have movie database has these tables: new_movies, ratings, critic_ratings, colors

i'm trying execute select statement combine these 4 tables on same movie using 'mid' (movie id):

select distinct     new_movies.*,    movies_db.*,    ratings.rating,    ratings.count,color,    critic_ratings.rating critic_ratings      new_movies  inner join     movies_db  on     new_movies.mid = movies_db.mid  left join     ratings  on     new_movies.mid = ratings.mid  left join     colors  on     new_movies.mid = colors.mid  left join     critic_ratings  on     new_movies.mid = critic_ratings.mid  order     title asc 

but error:

the select examine more max_join_size rows; check , use set sql_big_selects=1 or set sql_max_join_size=# if select okay

how query?

if don't want enable big selects, reform using correlated sub-queries. (i don't know if you'll still hit limit or not though.)

select distinct     new_movies.*,    movies_db.*,    (select rating ratings        new_movies.mid = ratings.mid) rating,    (select count  ratings        new_movies.mid = ratings.mid) rating_count,    (select color  colors         new_movies.mid = colors.mid)  colour,    (select rating critic_ratings new_movies.mid = critic_ratings.mid) critic_ratings    new_movies  inner join    movies_db      on new_movies.mid = movies_db.mid  order     title asc 

also, worth test see if left joins cause, can execute following?

select distinct     new_movies.*,    movies_db.*    new_movies  inner join    movies_db      on new_movies.mid = movies_db.mid  order     title asc 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -