dardime Posted March 7, 2017 Share Posted March 7, 2017 Hi I have 3 tables and i want to search record on 3 tables but when i query i noticed the row QUANTITY is used on stock_stockin_product and stock_product tables. When i displayed the output it shows the QUANTITY on tae stock_product which is i dont want it. I want to display QUANTITY on stock_stockin_product table. Here is my query: SELECT * FROM stock_stockin,stock_stockin_product,stock_product WHERE stock_date>='1488366000' AND stock_date<='1488538800' AND stock_product.brand_id='11' AND stock_product.category_id='27' AND stock_product.model LIKE '%iphone 6%' AND stock_stockin.branch LIKE '%henderson%' AND stock_product.id=stock_stockin_product.product_id AND stock_stockin.id=stock_stockin_product.stockin_id GROUP BY stock_stockin.id Output: All I need is the output QUANTITY 30 which i circled red. Thank you in advance for your help. Quote Link to comment https://forums.phpfreaks.com/topic/303376-multiple-tables-output-in-phpmyadmin/ Share on other sites More sharing options...
Solution Barand Posted March 7, 2017 Solution Share Posted March 7, 2017 (edited) Don't use "SELECT * ", specify the columns you need. Then apply aliases to differentiate between those with the same name. Use explicit join syntax. Example QUANTITY is used on stock_stockin_product and stock_product tables SELECT sip.quantity as quantity_sip , sp.quantity as quantity_sp , whatever_else FROM stock_stockin si INNER JOIN stock_stockin_product sip ON si.id=sip.stockin_id INNER JOIN stock_product sp ON sp.id=sip.product_id WHERE stock_date>='1488366000' AND stock_date<='1488538800' AND stock_product.brand_id='11' AND stock_product.category_id='27' AND stock_product.model LIKE '%iphone 6%' AND stock_stockin.branch LIKE '%henderson%' GROUP BY si.id Edited March 7, 2017 by Barand 1 Quote Link to comment https://forums.phpfreaks.com/topic/303376-multiple-tables-output-in-phpmyadmin/#findComment-1543855 Share on other sites More sharing options...
dardime Posted March 7, 2017 Author Share Posted March 7, 2017 Thank you bro Quote Link to comment https://forums.phpfreaks.com/topic/303376-multiple-tables-output-in-phpmyadmin/#findComment-1543888 Share on other sites More sharing options...
dardime Posted March 7, 2017 Author Share Posted March 7, 2017 Hi This gives me error SELECT sip.quantity as quantity_sip, sp.quantity as quantity_sp FROM stock_stockin si,stock_stockin,stock_stockin_product,stock_product INNER JOIN stock_stockin_product sip ON si.id=sip.stockin_id INNER JOIN stock_product sp ON sp.id=sip.product_id WHERE stock_date>='1488366000' AND stock_date<='1488538800' AND stock_product.brand_id='11' AND stock_product.category_id='27' AND stock_product.model LIKE '%iphone 6%' AND stock_sto Quote Link to comment https://forums.phpfreaks.com/topic/303376-multiple-tables-output-in-phpmyadmin/#findComment-1543891 Share on other sites More sharing options...
Barand Posted March 7, 2017 Share Posted March 7, 2017 Quite probably. You messed up the syntax. Quote Link to comment https://forums.phpfreaks.com/topic/303376-multiple-tables-output-in-phpmyadmin/#findComment-1543892 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.