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

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -