mysql GROUP_CONCAT update select help

Associate
Joined
18 Oct 2002
Posts
100
Hi

anyone know why this doesn't work.... it doesn't update any rows even though narrowby table has all of the nby_pid values

update narrowby set type_155=1 where nby_pid=(Select GROUP_CONCAT(product_id SEPARATOR ' or nby_pid=') AS 'nby_pid' From product_description Where name Like 'VTR%')

the above doesn't work then if I run this update with the sub query included it works (like below)

same query but broken down without the sub-select ....which does update fine

update narrowby set type_155=1 where nby_pid=12501 or nby_pid=12536 or nby_pid=12504 or nby_pid=12471 or nby_pid=12513 or nby_pid=12607 or nby_pid=12605 or nby_pid=12606 or nby_pid=12493 or nby_pid=12604 or nby_pid=12574 or nby_pid=12480 or nby_pid=12596 or nby_pid=12608 or nby_pid=12595 or nby_pid=12503 or nby_pid=12481 or nby_pid=12535 or nby_pid=12482 or nby_pid=12476 or nby_pid=12472 or nby_pid=12613 or nby_pid=12609 or nby_pid=12538 or nby_pid=12496 or nby_pid=12537 or nby_pid=12577

nby_id is primary & index

tried both 5.0.77 & 5.1.33 mysql versions

Thanks in advance

Slasher
 
Thanks... I do appreciate your help

Sorry I'm still learning :confused: .... is this what you mean't?

doesn't work
update narrowby set type_155=1 where nby_pid in ((Select GROUP_CONCAT(product_id) From product_description Where name Like 'VTR%'))

works perfectly but need the sub select to work
update narrowby set type_155=1 where nby_pid in (12501,12536,12504,12471,12513,12607,12605,12606,12493,12604,12574,12480,12596,12608,12595,12503,12481,12535,12482,12476,12472,12613,12609,12538,12496,12537,12577)

Sorry for sounding :confused:
I can't get my head around why if I break the above query down it works fine & the select works fine but joining the 2 together is a different matter

Can you give me an example with the query above how it should be written?

Thanks again
 
sorted it.....concat not group_concat

update narrowby set type_155=1 where nby_pid in ((Select CONCAT(product_id) as 'id' From product_description Where name Like 'VTR%'))

Many Thanks again
 
Last edited:
Thanks for all of the repies

Trying to format in this way (see below)

This query works but would like to be able to put some li span tags like below I know concat_ws allows formatting to this extent but group_concat doesn't

select atributes.Code, group_concat( atributes.name, atributes.value separator ' ' ) as `id` from atributes group by atributes.Code;


PHP:
Code   | name               | value 
-----------------------------------------
100246 | Item model number  | runner 9001
100246 | Weight             | 982g
100246 | Batteries          | 2 included
100557 | Item model number  | runner 9007
100557 | Weight             | 112g
100557 | Batteries          | 3 included

Code   | id             
-----------------------------------------
100246 |<li id='name'><span class='spec'>Item model number</span>runner 9001</li><li id='name'><span class='spec'>Weight</span>982g</li><li id='name'><span class='spec'>Batteries</span>2 included</li>
100557 |<li id='name'><span class='spec'>Item model number</span>runner 9007</li><li id='name'><span class='spec'>Weight</span>112g</li><li id='name'><span class='spec'>Batteries</span>3 included</li>

any ideas?

Thanks in advance
 
Sorry had to go away family issues :(

Thanks for all of the replies

Trying to update from 1 table to another with a sub select query

Code:
update test, atributes
set
test.spec=(SELECT GROUP_CONCAT(CONCAT_WS('','<li><span class="spec">', atributes.FriendlyName3, '</span>', atributes.AttributeValue,'</li>') SEPARATOR '') as spec FROM atributes group by Code)
where 
test.Code=atributes.Code

get error 1242 subquery returns more than 1 row

How do I get this to work, is it possible?

Thanks in advance
 
Back
Top Bottom