I'm having problems writing this one particular query. I have two tables, CARRIER and PATIENTS. There's a one-to-many relationship between the two. Basically, in one query, I want to pull the CARRIERNAME and CARRIERADDRESS of every CARRIER record in addition to a count of how many PATIENTS records have that particular CARRIERID. Does that make sense? So far I've tried:
SELECT ic.id,ic.name,ic.carrieraddress,ic.carriercity,ic.carrierstate,ipp.id
FROM carrier ic, patient_procedure ipp
WHERE ic.deleted=0 AND
ic.id = ipp.carrier_id
ORDER BY ic.name;
Which doesn't work, and:
SELECT ic.id,ic.name,ic.carrieraddress,ic.carriercity,ic.carrierstate,count(ipp.id)
FROM carrier ic, patient_procedure ipp
WHERE ic.deleted=0 AND
ic.id = ipp.carrier_id
ORDER BY ic.name;
Which also doesn't work. Any thoughts on where I'm going wrong? Thanks!
Here's the structure of the tables:
CARRIER:
id
name
carrieraddress
carriercity
carrierstate
deleted
PATIENT_PROCEDURE:
id
name
carrier_id