add batch
remove batch
split batch
comment selection
show hidden batches
hide batch
highlight batch
db<>fiddle
Db2
Firebird
MariaDB
MySQL
Node.js
Oracle
Postgres
SQLite
SQL Server
TimescaleDB
YugabyteDB
Developer-C 11.1
3.0
4.0
10.2
10.3
10.4
10.5
10.6
10.7
10.8
10.9
5.5
5.6
5.7
8.0
18
11g Release 2
18c
21c
23c
8.4
9.3
9.4
9.5
9.6
10
11
12
13
14
15
16
3.8
3.16
3.27
3.39
2012
2014
2016
2017
2017 (Linux)
2019
2019 (Linux)
2022
2.11
2.14
2.6
2.8
2.18
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
Sakila
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
AdventureWorks
no sample DB
no sample DB
AdventureWorks
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
run
markdown
donate
feedback
about
By using db<>fiddle, you agree to license everything you submit by
Creative Commons CC0
.
CREATE TABLE `team` ( `Team_ID` bigint(20) NOT NULL AUTO_INCREMENT, `Founder_ID` bigint(20) DEFAULT NULL, `Team_Logo` varchar(255) DEFAULT NULL, `Team_Name` varchar(255) DEFAULT NULL, PRIMARY KEY (`Team_ID`) ) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=latin1; /*Data for the table `team` */ insert into `team`(`Team_ID`,`Founder_ID`,`Team_Logo`,`Team_Name`) values (4,1,'486396439.png','Team 1'), (11,9,'531151623.png','Team 2'), (13,7,'557132285.png','Team 3'); /*Table structure for table `team_member` */ DROP TABLE IF EXISTS `team_member`; CREATE TABLE `team_member` ( `Team_Member_ID` bigint(20) NOT NULL AUTO_INCREMENT, `Team_ID` bigint(20) DEFAULT NULL, `Team_User_ID` bigint(20) DEFAULT NULL, `Team_UserName` varchar(255) DEFAULT NULL, `IsTeamLead` tinyint(1) DEFAULT NULL, `IsFounder` tinyint(1) DEFAULT '0', PRIMARY KEY (`Team_Member_ID`) ) ENGINE=InnoDB AUTO_INCREMENT=131 DEFAULT CHARSET=latin1; /*Data for the table `team_member` */ insert into `team_member`(`Team_Member_ID`,`Team_ID`,`Team_User_ID`,`Team_UserName`,`IsTeamLead`,`IsFounder`) values (13,4,3,'ABC',0,0), (14,4,4,'DEF',0,0), (15,4,5,'SpiderMan',1,0), (16,4,6,'Antman',0,0), (17,4,7,'Boost',0,0), (121,11,1,'Nishanth',1,0), (122,11,2,'Superman',0,0), (123,11,3,'Batman',0,0), (128,12,10,'Hulk',0,0), (129,13,12,'CAmerica',1,0), (130,13,13,'Arrow',0,0); /*Table structure for table `teams_game_match` */ CREATE TABLE `teams_game_match` ( `game_match_id` bigint(20) NOT NULL AUTO_INCREMENT, `created_team_id` bigint(20) DEFAULT NULL, `game_date` date DEFAULT NULL, `game_time` varchar(50) DEFAULT NULL, `game_name` varchar(50) DEFAULT NULL, `team_1_id` bigint(20) DEFAULT NULL, `team_2_id` bigint(20) DEFAULT NULL, `team_1_name` varchar(50) DEFAULT NULL, `team_2_name` varchar(50) DEFAULT NULL, `assigned_user_id` bigint(20) DEFAULT NULL, `game_id` bigint(20) DEFAULT NULL, `accept` tinyint(1) DEFAULT '0', PRIMARY KEY (`game_match_id`) ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1; /*Data for the table `teams_game_match` */ insert into `teams_game_match`(`game_match_id`,`created_team_id`,`game_date`,`game_time`,`game_name`,`team_1_id`,`team_2_id`,`team_1_name`,`team_2_name`,`assigned_user_id`,`game_id`,`accept`) values (1,11,'2019-06-28','1:30am','Battlefield 4',11,4,'yrtn','Nish',9,1,0), (7,13,'2019-07-12','1:30am','FIFA 17',13,11,'BFM','yrtn',12,1,1);
select max(case when flag=1 then oponent_Team_ID end) as oponent_Team_ID, max(case when flag=0 then oponent_Team_ID end) as opposer_Team_ID from ( SELECT DISTINCT `team_member`.`Team_ID` AS oponent_Team_ID, `team`.`Founder_ID` AS oponent_Founder_ID, `team`.`Team_Logo` AS oponent_Team_Logo, `team`.`team_Name` AS oponent_Founder_Name, `teams_game_match`.`team_1_id` AS oponent_team_1_id, `teams_game_match`.`team_2_id` AS oponent_team_2_id, `teams_game_match`.`game_time` AS oponent_game_time, `teams_game_match`.`game_date` AS oponent_game_date, `teams_game_match`.`game_name` AS oponent_game_name, `teams_game_match`.`accept` AS oponent_accept, 1 as flag FROM `team_member` JOIN `team` ON `team_member`.`Team_ID` = `team`.`Team_ID` JOIN `teams_game_match` ON `teams_game_match`.`team_2_id` = `team`.`Team_ID` WHERE `teams_game_match`.`team_1_id` = '11' UNION SELECT DISTINCT `team_member`.`Team_ID` AS opposer_Team_ID, `team`.`Founder_ID` AS opposer_Founder_ID, `team`.`Team_Logo` AS opposer_Team_Logo, `team`.`team_Name` AS opposer_Founder_ID, `teams_game_match`.`team_1_id` AS opposer_team_1_id, `teams_game_match`.`team_2_id` AS opposer_team_2_id, `teams_game_match`.`game_time` AS opposer_game_time, `teams_game_match`.`game_date` AS opposer_game_date, `teams_game_match`.`game_name` AS opposer_game_name, `teams_game_match`.`accept` AS opposer_accept,0 FROM `team_member` JOIN `team` ON `team_member`.`Team_ID` = `team`.`Team_ID` JOIN `teams_game_match` ON `teams_game_match`.`team_1_id` = `team`.`Team_ID` WHERE `teams_game_match`.`team_2_id` = '11' )A
oponent_Team_ID
opposer_Team_ID
4
13