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.
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'