mysql - Comparing values from two different tables while inserting into another 'middle table' -


so have 2 tables

club - id_club, name, nationality

and

league - id_league, name, nationality

between them middle table "play at" connects id of club league id -> specifies in league club play. there way check if club's nationality equals leagues nationality while inserting club league through middle table? want secure example spanish club can play in spanish league. thank aswers.

is there way check if club's nationality equals leagues nationality

yes, simple inner join between tables like

select c.id_club,  c.name,  c.nationality, l.id_league,  l.name club c join league l on c.nationality = l.nationality; 

(or) using where exists

select c.id_club,  c.name,  c.nationality club c  exists(select 1 league c.nationality = nationality); 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -

r - Update two sets of radiobuttons reactively - shiny -