Jump to content

is this possible


mahenda

Recommended Posts

//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 = '.....';

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.