How do i join two tables in a database using MySQL with specific names -


i have movies database using mysql in xampp. has 3 tables

movies(movieid(pk), title, rating, genre, release_date), actors(actorid(pk), firstname,lastname,gender, date_of_birth), , actorsmovies(actorid(pk),movieid(pk).

i have display fields movies michael j. fox actor. how join 2 tables show me movies michael j fox in? actorsmovies has constraints on it.

example: ive tried million combinations example

select firstname,lastname,title actors firstname,lastname = 'michael j','fox' join actorsmovies on actors.actorid = actorsmovies.actorid join movies on actorsmovies.movieid = movies.movieid;

you have

select firstname,lastname,title  actors    firstname,lastname = 'michael j','fox'  join actorsmovies    on actors.actorid = actorsmovies.actorid  join movies on actorsmovies.movieid = movies.movieid; 

and need

select firstname,lastname,title  actors  join actorsmovies    on actors.actorid = actorsmovies.actorid  join movies on actorsmovies.movieid = movies.movieid firstname = 'michael j' , lastname 'fox'; 

simply put, clause has after joins , before order group , having. recommend being more explicit on clause , spelling out , readability.

now if joins outer joins may need mvoe limit critiera

say in example want movies , want "hilight" ones michael j fox... right join here returnss movies titles , firstname,lastname not blank when it's michael j. fox. otherwise blank!

select firstname,lastname,title  actors  join actorsmovies    on actors.actorid = actorsmovies.actorid  , actors.firstname = 'michael j' , actors.lastname 'fox'; right join movies on actorsmovies.movieid = movies.movieid; 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -