Jump to content

[SOLVED] inner joins


stockdalep

Recommended Posts

Hi

 

Could anyone help me with this I need to join one more table to this query named

mens_dc  I have tried various syntex but to no avail.

 

$result = mysql_query("select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" .  GetCartId() . "' order by

items.itemName asc");

 

Thanks for any help

Link to comment
Share on other sites

Well first I have to know what mens_dc joins on. I assumed here that it was on the mdcID column. Change it to suit.

SELECT * 
FROM cart
JOIN items ON cart.itemID  = items.itemID
JOIN mens_dc ON items.mdcID = mens_dc.mdcID
WHERE cart.cookieID = '$cartID'
ORDER BY items.itemName "

Link to comment
Share on other sites

This is what we have now but it still does not work.

 

$result = mysql_query("SELECT * FROM cart inner JOIN items ON cart.itemId  = items.itemId inner JOIN mens_dc ON mens_dc.itemId = mens_dc.itemId WHERE cart.cookieId = GetCartId()");

 

Original code

 

$result = mysql_query("select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" .  GetCartId() . "' order by

items.itemName asc");

 

Link to comment
Share on other sites

Hi

 

I have 3 Tables as below I am trying to join both mens_dc and items tables to cart.

If I use this sql

=========================================================

$result = mysql_query("select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" .  GetCartId() . "' order by

items.itemName asc");

=========================================================

We get the records from the items table but I cannot get both tables if I try

=========================================================

select * from cart

inner join items on cart.itemId = items.itemId

inner join items on cart.itemId = items.itemId

where cart.cookieId =  '" .  GetCartId() . "' order by

items.itemName asc

=====================================================

We then get nothing any ideas would be gratefully received

Thanks.

 

======================================

Table Cart

 

              |cartId | cookieId | itemId | qty |

Data            18      12344        2        1

                  19      12344        15      3

======================================

Table items

 

              |itemId |itemName | itemDesc | itemPrice |

Data            2    Trouser        Trouser        5.50

 

======================================

 

Table mens_dc

 

              |itemId |itemName | itemDesc | itemPrice |

Data            15      Curtain      Curtain        26.00

 

======================================

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.