mahenda Posted April 4, 2021 Share Posted April 4, 2021 //look my code CREATE TABLE IF NOT EXISTS first ( fid int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, p_name varchar(60) NOT NULL ); CREATE TABLE IF NOT EXISTS second ( sed int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, firstname varchar(20) NOT NULL, fid int(11) NOT NULL, FOREIGN KEY (fid) REFERENCES first(fid) ); CREATE TABLE IF NOT EXISTS third ( thid int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, start_date date NOT NULL, end_date date NOT NULL, sed int(11) NOT NULL, FOREIGN KEY (sed) REFERENCES second(sed), fid int(11) NOT NULL, FOREIGN KEY (fid) REFERENCES first(fid) ); CREATE TABLE IF NOT EXISTS fourth ( fid int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, start_date date NOT NULL, end_date date NOT NULL, sed int(11) NOT NULL, FOREIGN KEY (sed) REFERENCES second(sed), fid int(11) NOT NULL, FOREIGN KEY (fid) REFERENCES first(fid) ); CREATE TABLE IF NOT EXISTS fifth ( fiid int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, start_date date NOT NULL, end_date date NOT NULL, sed int(11) NOT NULL, FOREIGN KEY (sed) REFERENCES second(sed), fid int(11) NOT NULL, FOREIGN KEY (fid) REFERENCES first(fid) ); CREATE TABLE IF NOT EXISTS sixth ( sid int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, start_date date NOT NULL, end_date date NOT NULL, sed int(11) NOT NULL, FOREIGN KEY (sed) REFERENCES second(sed), fid int(11) NOT NULL, FOREIGN KEY (fid) REFERENCES first(fid) ); //As you can see above, I want to create a single query to query all data at the samee time i.e //All table from third table depend on first and second table, but the second table have column firstname and the first table has the p_name column //I want SELECT second.*, third.* FROM second INNER JOIN third ON third.sed = second.sed SELECT second.*, fourth.* FROM second INNER JOIN fourth ON fourth.sed = second.sed SELECT second.*, fifth.* FROM second INNER JOIN fifth ON fifth.sed = second.sed SELECT second.*, sixth.* FROM second INNER JOIN sixth ON sixth.sed = second.sed ....WHERE fid = 1; //I want to combine these queries into single query ie, $newqueries = '.....'; Quote Link to comment Share on other sites More sharing options...
Barand Posted April 4, 2021 Share Posted April 4, 2021 (edited) Why would you want to do that? Table third, fourth, fifth and sixth all have identical structures - combine into a single table with atype identifier column. It will make life much simpler. becomes Edited April 4, 2021 by Barand 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.