sql query - how to include columns in a group by query which are not in the "group by"? -


there 2 tables involved in question:

table1:

patientmaster:  patientid, patientname 

table2:

medicinemaster:  medicineid, patientid, medicinename 

in table 2, many medicines single patient stored...

but need patientid , patientname table 2..

my qry is,

select med.medicineid,        pat.patientname  medicinemaster med    join patientmaster pat on med.patientid = pat.patientid  group pat.patientname 

but error came,

column 'medicinemaster.medicineid' invalid in select list because not contained in either aggregate function or group clause.

i result this:

patientid  patientname 3          xx 4          yy 

to me seems after patients' details have medicine. use following query:

select distinct pat.patientid, pat.patientname medicinemaster med  inner join patientmaster pat on pat.patientid = med.patientid 

since not using kind of aggregation function (sum, count, avg, , on) don't need group data.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -