Monday, March 12, 2012

Mysql Vs Mssql query

Hi,
I have a query that works perfectly in Mysql but fails in MSSQL.
Can anyone please throw light on this issue and guide me on how to avoid
this?
quote:

select cust_name,cust_email from customer,cust_departments
where customer.cust_id=cust_departments.cust_id and
cust_departments.dept_id='1' and cust.notify_ticket='1' group by
cust_departments.cust_id


The error thrown is Column 'cust_name' is invalid in the select list because
it is not contained in either an aggregate function or the GROUP BY clause.
What do I do?
Thanks and Regards,
Celia>
quote:

> select cust_name,cust_email from customer,cust_departments
> where customer.cust_id=cust_departments.cust_id and
> cust_departments.dept_id='1' and cust.notify_ticket='1' group by
> cust_departments.cust_id
>

I have no idea what you expect to see in MySQL. Why are using GROUP BY? Do
you multiple cust_name/cust_email combinations for a single cust_id? If so,
which one do you expect to show (I assume you only want one cust_id per
row)?
Perhaps you could provide schema (I have no idea what table cust_name /
cust_email belong to), sample data and desired results as per
http://www.aspfaq.com/5006|||Does MySQL not have DISTINCT? Is that why the group by is being used?
Also you should not use the old join style - update it to the ANSI syntax
select DISTINCT cust_name,cust_email
from customer
join cust_departments on customer.cust_id=cust_departments.cust_id and
cust_departments.dept_id='1'
where cust.notify_ticket='1'
celia wrote:
> Hi,
> I have a query that works perfectly in Mysql but fails in MSSQL.
> Can anyone please throw light on this issue and guide me on how to avoid
> this?
>
quote:

> select cust_name,cust_email from customer,cust_departments
> where customer.cust_id=cust_departments.cust_id and
> cust_departments.dept_id='1' and cust.notify_ticket='1' group by
> cust_departments.cust_id
>

> The error thrown is Column 'cust_name' is invalid in the select list becau
se
> it is not contained in either an aggregate function or the GROUP BY clause
.
> What do I do?
> Thanks and Regards,
> Celia
>

No comments:

Post a Comment