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 -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -