mysql - Best way to join this query -


i have following tables , data:

tables ----------- create table primarys  ( primaryid bigint(20) not null auto_increment, primary key (primaryid));  create table patients ( primaryid bigint(20) not null, patientid bigint(20), patientname varchar(50), primary key (primaryid));  create table patientvisit ( primaryid bigint(20) not null, visitid bigint(20), visitdate date, primary key (primaryid));  data --------- insert primarys values (1); insert primarys values (7286); insert primarys values (7287);  insert patients values (1,'1','john'); insert patients values (7286,'1', ''); insert patients values (7287,'1', '');  insert patientvisit values (7286,'1','1997-12-18'); insert patientvisit values (7287,'2','1998-02-25'); 

i need write query outputs data follows:

primaryid   |  patientid    |   patientname    |  visit   |  visitdate ------------------------------------------------  7286        |   1           |  john            |   1      |  1997-12-18 7287        |   1           |  john            |   2      |  1998-02-25 

i can figure out how outer joins , sub queries work fine when start adding large data set mysql performance begins decrease.

i grateful if suggest optimised way query these data , desired output.

thanks

for specific values display in question, query do.

select q2.primaryid, q_1, q_2, q_4, q_5 questions_101_200 q2 cross join questions_1_100  

but data , structure doesn't make sense me. if explain more trying do, can give more meaningful answer.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -