Current location: Hot Scripts Forums » Other Discussions » Database » Report Post This simple joing mysql select return many duplicate results


Report Post This simple joing mysql select return many duplicate results

Reply
  #1 (permalink)  
Old 10-27-09, 02:09 PM
m_abdelfattah m_abdelfattah is offline
Newbie Coder
 
Join Date: Sep 2004
Location: Alexandria, Egypt.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Report Post This simple joing mysql select return many duplicate results

I've problem with this query :
MySQL pastebin - collaborative debugging tool ,

It returns many duplicated results ,
here's image : Imageshack - mysqlun - Uploaded by alex_funky_dj
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-03-09, 11:46 AM
carters-site's Avatar
carters-site carters-site is offline
Wannabe Coder
 
Join Date: Sep 2009
Location: Moline, IL
Posts: 100
Thanks: 2
Thanked 1 Time in 1 Post
IF there keys you can join the tables on you should do so. Also you can use SELECT DISTINCT to elimate dup rows if they are in fact the same.

Another tip is to only query for the actual data you need.

You original link to your query does not work you can just post the query in between some code blocks on this forum and we can look at it there. Your schema is also helpful.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 11-03-09, 12:52 PM
m_abdelfattah m_abdelfattah is offline
Newbie Coder
 
Join Date: Sep 2004
Location: Alexandria, Egypt.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
The problem was because of not using LEFT JOIN, I did used LEFT JOIN and everything went fine.
Oh, sorry for this, Here's the Code :
Code:
SELECT `transactions`.*, `transaction_details`.*, `product_items`.`name` AS `product_name`, `branches`.`name` AS `branch_name` FROM `transactions`, `transaction_details`, `product_items`, `branches` WHERE `transactions`.`retailer_id` = '1' AND `transactions`.`transaction_id` = '5'
and I'd replaced it with :
Code:
SELECT `transactions`.*, `transaction_details`.*, `transactions`.`total_price` AS `transaction_total_price`, `transactions`.`original_total_price` AS `transaction_original_total_price`, `product_items`.`name` AS `product_name`, `branches`.`name` AS `branch_name`, `clients_suppliers`.`name` AS `client_supplier_name`, `users`.`name` AS `user_name`
    FROM `transactions`
    LEFT JOIN `transaction_details` on `transactions`.`transaction_id` = `transaction_details`.`transaction_id`
    LEFT JOIN `product_items` on `product_items`.`product_id` = `transaction_details`.`product_id`
    LEFT JOIN `branches` on (
        `branches`.`branch_id`= IF(`transactions`.`from_branch_id`>0,`transactions`.`from_branch_id`, `transactions`.`to_branch_id`)
                                                                                                    )
    LEFT JOIN `clients_suppliers` on `transactions`.`client_supplier_id` = `clients_suppliers`.`client_supplier_id`
    LEFT JOIN `users` on `transactions`.`user_id` = `users`.`user_id` 
    WHERE `transactions`.`retailer_id` = '1'
        AND `transactions`.`transaction_id` = '5'
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 11-03-09, 02:57 PM
carters-site's Avatar
carters-site carters-site is offline
Wannabe Coder
 
Join Date: Sep 2009
Location: Moline, IL
Posts: 100
Thanks: 2
Thanked 1 Time in 1 Post
Great glad you got it working.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
TreeView Control - Background Image? tim8w Windows .NET Programming 1 04-11-07 01:43 PM
sessions writing to mysql report errors perleo PHP 5 08-30-05 03:33 PM
how to weigh mysql select results bugalyzer PHP 1 02-28-05 01:38 PM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 05:28 PM
Help trim code down TheLaughingBandit JavaScript 0 09-02-03 10:50 AM


All times are GMT -5. The time now is 10:42 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.