Solved. Look in comment.
I am using PostgreSQL 9.1. I have 3 tables:
- simcards: id serial NOT NULL, iccid character varying(30) NOT NULL, customer_id integer
- customer: id serial NOT NULL, name character varying(50) NOT NULL
- topup: id serial NOT NULL, amount integer NOT NULL, iccid_id integer NOT NULL
And now when I select some simcards I would like to get extra column that shows value yes/no, true/false, 1/0 if this simcard has also a record in topup table (if had been toped up).
I think I have to use LEFT JOIN but I don't know how to display only value true/false. Here is my current SQL that shows everything form topup table:
select b.iccid, b.phone_number, d.name as customer, t.* from simcard_simcard as b join simcard_customer as d on b.customer_id = d.id left join simcard_topup as t on b.id = t.iccid_id where d.name = 'THREE'
Can you give me any suggestions? Thanks