i have an sql query that does not work the way i want ,how to do what i want?

nicedone
nicedone used Ask the Experts™
on
f sda
In 1.jpg you can see I have 3 tables

hasta,(hasta_id,hasta_adi,telefon,adres)
operasyon,(operasyon_id,islem_id,doktor_id,hasta_id,operasyon_tutar,operasyon_aciklama,kalan_borc)
islem,(islem_id,islem_adi)

The problem is when i add 4th table which is called Odeme

Odeme(odeme_id,operasyon_id,odeme_aciklama,odeme_tutar)

I dont get any results somehow but i need information from the 4th table as well but i can not get somehow !!!

what i am try to do is display selected patient's information in datagrid.

hasta=patient
operasyon=operations
islem=list of available operations
odeme=payments

I save patients in patients table and if i can choose a patient and assing him/her operation from the list of available operations
then i can also enter payment to the specific operation


Pls help...
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You will really want to change this query to use JOINs (http://www.w3schools.com/sql/sql_join.asp) instead of using multiple tables in the SELECT. Try the below:

SELECT 
  h.hasta_adi, h.telefon, h.adres,
  i.islem_adi,
  o.operasyon_tutar, o.kalan_borc, o.operasyon_aciklama, 
  od.odeme_tutar, od.odeme_aciklama
FROM Hasta As h
LEFT JOIN Operasyon As o ON o.hasta_id=h.hasta_id
LEFT JOIN Islem As i ON o.islem_id=i.islem_id
LEFT JOIN Odeme As od ON od.operasyon_id=o.operasyon_id
WHERE h.hasta_id='62'

Open in new window

Top Expert 2012
Commented:
It is quite simple you do not have any values in operasyon_id in Odeme that match the corresponding values in Operasyon
When you use links in such a way, make sure you do not have NULL values, otherwise, results will be empty.

Author

Commented:
thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial