Jump to content

[SOLVED] Even tricker one


jwwceo

Recommended Posts

I have another tricky query which I can't seem to get working:

 

There are 4 tables, with various links to one another. I want to update the value image_path in one table, based on the values from 2 other tables. The two values for this particluar query are

 

productid: 16150

option_name: Black

 

Here is the code I have so far:

 

Thanks!!!

 


UPDATE xcart_images_W SET image_path = 'test.png'

INNER JOIN xcart_variants.variantid ON xcart_variant_items.variantid
INNER JOIN xcart_variant_items.optionid ON xcart_class_options.optionid
INNER JOIN xcart_variants.variantid ON xcart_images_W.id

WHERE

xcart_variants.productid = '16150' AND
xcart_class_options.option_name = 'Black'





Link to comment
Share on other sites

I made the changes you said and I get this error. I really appreciate the help with this..

 

#1066 - Not unique table/alias: 'variantid'

 

Here's what I used...

 

 UPDATE xcart_images_W 
INNER JOIN xcart_variants.variantid ON xcart_variant_items.variantid 
INNER JOIN xcart_variant_items.optionid ON xcart_class_options.optionid 
INNER JOIN xcart_variants.variantid ON xcart_images_W.id 
SET image_path = 'test.png' 
WHERE xcart_variants.productid = '16150' 
AND xcart_class_options.option_name = 'Black'  

Link to comment
Share on other sites

I got it working using this. I was failing to list all the tables in the UPDATE line, even if they aren't being updated

 

UPDATE xcart_images_W, xcart_variants, xcart_variant_items, xcart_class_options

SET xcart_images_W.image_path = 'test1.png' 
WHERE xcart_variants.variantid = xcart_variant_items.variantid 
AND xcart_variant_items.optionid = xcart_class_options.optionid 
AND xcart_variants.variantid = xcart_images_W.id 
AND xcart_variants.productid = '16150' 
AND (xcart_class_options.option_name = 'Black' 
OR xcart_class_options.option_name = 'Gold'
OR xcart_class_options.option_name = 'Navy')

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.