Jump to content

Multiple Tables Output in phpmyadmin


dardime
Go to solution Solved by Barand,

Recommended Posts

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:

 

 

2wqcutv.jpg

 

All I need is the output QUANTITY 30 which i circled red. Thank you in advance for your help. 

 

 

Link to comment
Share on other sites

  • Solution

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 by Barand
  • Like 1
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.