MySQL: Finding id's in separate tables with identical groups of records -


i have 2 different tables of records having same sub groups of information, both having different id values. below example have table of actors movies , plays.

i query these 2 tables such pair of movie_id, play_id values have same actors (i.e. have first_name = given_name , last_name = family_name each record same id).

what appropriate query accomplish this?

table: movie_actors | movie_id | first_name | last_name | |----------+------------+-----------| |        1 |       mary |   johnson | |        1 |       john |     smith | |        2 |        tom |  anderson |  table: play_actors |  play_id | given_name | family_name | |----------+------------+-------------| |       23 |       mary |     johnson | |       23 |       john |       smith | |       31 |       marc |     anthony |   desired output: | movie_id | play_id | |----------+---------| |        1 |      23 | 

use group_concat in subqueries actors single column. join subqueries based on this.

select movie_id, play_id (select movie_id, group_concat(concat(first_name, '-', last_name) order first_name, last_name) actors       movie_actors       group movie_id) m join (select play_id, group_concat(concat(given_name, '-', family_name) order given_name, family_name) actors       play_actors       group play_id) p on m.actors = p.actors 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -