+2  A: 

The join syntax is very straightforward in SQL. You are probably looking for something like this:

SELECT   reservation.patient_id, 
         sub_unit.sub_unit_name, 
         patient.patient_name, 
         patient.address
FROM     reservation
JOIN     patient ON (patient.id = reservation.patient_id)
JOIN     sub_unit ON (sub_unit.id = reservation.sub_unit_id);

In MySQL, the default join is an Inner Join, which I think is what you're looking for. You may also want to look into Outer Joins which are also very useful.

Daniel Vassallo
+2  A: 
Select r.patient_id, s.sub_unit_name, p.patient_name, p.address 
from reservation r, sub_unit s, patient p 
where r.patient_id = p.patient_id and r.sub_unit_id = s.sub_unit_id 
Barun
A: 

it worked guys , i did it like this using Codeigniter active records ,hope you guys can use it too

    function get_data(){
    $sql = 'SELECT * FROM visit,patient,sub_unit WHERE visit.patient_patient_id = patient.patient_id AND visit.sub_unit_sub_unit_id = sub_unit.sub_unit_id';

    $this->db->order_by("reference_number", "desc");
    $query = $this->db->query($sql);
    return $query;
}

thanx for all your support!

ranganaMIT
@ranganaMIT: You're using the very old ANSI-89 join syntax in that query (also called an implicit join), instead of the more popular (and modern) ANSI-92 syntax (also called explicit join). While most modern databases will treat both variants in the same way, it is generally recommended to stay away from the old syntax. It is less understandable, since you add an extra expression in the `WHERE` clause for each join, and it is also much easier to forget a join expression.
Daniel Vassallo
thank you very much for that comment Daniel,,, i will study about that! I'm only familiar with this type, that's why i used it!
ranganaMIT
+4  A: 

Using code igniter syntax it can be done as follows -

$this->db->select('r.patient_id, s.sub_unit_name, p.patient_name, p.address');
$this->db->from('reservation r');
$this->db->join('patient p', 'p.id = r.patient_id');
$this->db->join('sub_unit s', 's.id = r.sub_unit_id');
$query = $this->db->get();


You can check your formed query by -
echo $this->db->_compile_select();exit;
Alpesh
thank you very much for this answer, this is more familiar to me than the solution i found... !
ranganaMIT