-5

i have three relational tables. i want to show all records against code from patient_Record table. i want display record by patient_record code and by patient name and by date_time

here patient_record table[table1]

https://i.stack.imgur.com/59Xiz.png

here patient_checkup table[table2]

https://i.stack.imgur.com/KM6Q8.png

here patient_medicine table[table 3]

https://i.stack.imgur.com/k3POb.png

Dharman
  • 30,962
  • 25
  • 85
  • 135
muneeb
  • 1
  • 1

2 Answers2

0
SELECT *
FROM table1
    LEFT JOIN table2 ON table1.code=table2.checkup_code 
where table1.code = 32;
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Maulik
  • 1
0

I guess you want to join your tables over code -> checkup_code and then display all rows with patient_code = 32. Then your query needs to look like this:

SELECT    `table1`.`code`,
          `table1`.`date_time`,
          `table1`.`patient_code`,
          `table2`.`code`,
          `table2`.`checkup_code`,
          `table2`.`medicine`,
          `table2`.`potency`

FROM      `table1`

LEFT JOIN `table2.`
ON        `table2.`.`checkup_code` = `table1`.`code`

WHERE     `table1`.`patient_code` = '32' 

Note that SELECT * won't work because both your tables have a column code. For more information look here

wayneOS
  • 1,427
  • 1
  • 14
  • 20