在mysql中无法正常工作. [英] distinct in mysql is not working.

查看:722
本文介绍了在mysql中无法正常工作.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

在我的MySQL查询中,distinct无法正常工作.检索记录时,我得到重复的记录.

代码:

Hi friends,

In my MySQL query distinct is not working properly.I am getting duplicate records at the time of retrieving records.

code:

SELECT DISTINCT  slip_header_trn.slip_no, slip_header_trn.com_cd, slip_header_trn.cust_cd, slip_header_trn.entry_div, slip_header_trn.dest_cd, slip_header_trn.est_date,slip_header_trn.entry_date,slip_header_trn.order_date,slip_header_trn.delivery_comp_date, slip_header_trn.status_cd, slip_details_trn.model_cd, slip_details_trn.item_cd, model_mst.model_nm, destination_mst.dest_name, customer_mst.cust_nm, user_mst.user_nm, supplier_mst.sup_nm, company_mst.com_name FROM slip_header_trn LEFT OUTER JOIN slip_details_trn ON slip_header_trn.slip_no = slip_details_trn.slip_no LEFT OUTER JOIN customer_mst ON slip_header_trn.cust_cd = customer_mst.cust_cd LEFT OUTER JOIN destination_mst ON slip_header_trn.dest_cd = destination_mst.dest_cd LEFT OUTER JOIN supplier_mst ON slip_details_trn.sup_cd = supplier_mst.sup_cd LEFT OUTER JOIN user_mst ON slip_header_trn.user_id = user_mst.user_id  LEFT OUTER JOIN model_mst ON slip_details_trn.model_cd = model_mst.model_cd LEFT OUTER JOIN company_mst ON slip_header_trn.com_cd = company_mst.com_cd WHERE slip_header_trn.del_flg = 0

推荐答案



根据我对DISTINCT用法的了解,要获得更好且确实不同的结果,您必须在表上投影一列"!

您要为数据库提供大量工作/开销,以便根据发布的查询尝试对10多个列执行不同的搜索.有时最好以整数,字符列或数据较少的列为目标.

试想一下,如果您的老板要求您同时使用10种以上的语言编写代码?您当然可能知道10种以上的语言,但是您的性能会下降,并且结果可能不如预期-正是为什么您仍然在使用DISTINCT的查询中得到重复的行!因为就像你一样困惑...

祝你好运.
Hi,

According to my knowledge on DISTINCT usage, for better and indeed distinct results you have to "Project One Column" on your table!

You are giving your database alot of work/overhead to try and perform a distinct search on more 10 columns as per query posted. It''s good practice to sometimes target integer, char columns or columns with less data.

Just imagine if your boss asked you to code in more than 10 languages at the same time? you may ofcourse know more than 10 languages but your performance will drop-dead and the results may be not as expected - exactly why you are still getting duplicate rows in your query that is using DISTINCT! coz it''s just as confused as u would be...

Good luck.


这篇关于在mysql中无法正常工作.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆