Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi friends,

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

code:
SQL
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
Posted
Updated 12-Sep-11 20:12pm
v3
Comments
Mehdi Gholam 13-Sep-11 1:10am    
Post your code
Pravin Patil, Mumbai 13-Sep-11 1:19am    
Maybe you are using Distinct wrongly. Post your query..
Prerak Patel 13-Sep-11 2:13am    
Added code block.
Herman<T>.Instance 13-Sep-11 3:55am    
with all these LEFT OUTER JOINS......you are begging for duplicates

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900