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
解决方案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.