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
https://forums.phpfreaks.com/topic/78212-solved-even-tricker-one/
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'  

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')

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.