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
https://forums.phpfreaks.com/topic/43383-solved-inner-joins/
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
https://forums.phpfreaks.com/topic/43383-solved-inner-joins/#findComment-210716
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
https://forums.phpfreaks.com/topic/43383-solved-inner-joins/#findComment-210772
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
https://forums.phpfreaks.com/topic/43383-solved-inner-joins/#findComment-211146
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.