Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

SQL Help please?

  • 18-12-2007 10:33am
    #1
    Registered Users, Registered Users 2 Posts: 1,127 ✭✭✭


    Been wracking my brains (and Googles!) for the past little while on this. Can someone transcribe the following pseudocode to SQL for me (Im using MySQL version 5.0.27).
    for each item in (select product_id AS id from products where manu_id = x)
    do
         update descriptions set url = y where products_id = $id (from above)
    done
    

    make sense?


Comments

  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    I would imagine this could be done with a nested select.

    Have something like:
     update descriptions set url = y 
    where (products_id = 
    (select product_id from products where manu_id = x))
    

    Havn't tested and prob wont' even work but I don't want to help you too much due to the rules here :)
    [/code]


  • Registered Users, Registered Users 2 Posts: 1,127 ✭✭✭smcelhinney


    Rules, mwah hah!! I laugh in the face of rules.. but on a serious note, I wasnt aware that I was breaking the charter? Posted pseudo-code? Asked questions, not for homework, its a website Im working on and have exhausted other avenues..

    Thanks for the attempt though Webmonkey, have tried it and tis giving me "Subquery returns more than one row" error. And Im trying to tell the compiler "Well, hell yeah! Thats what its supposed to do?" but its not listening to me..

    Oh well, back to google.


  • Registered Users, Registered Users 2 Posts: 1,127 ✭✭✭smcelhinney


    Ah.. got it..
     update descriptions set url = y 
    where (products_id [B]IN[/B] (select product_id from products where manu_id = x))
    

    Thanks


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    This thread is certified charter breakingness free :)


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Rules, mwah hah!! I laugh in the face of rules.. but on a serious note, I wasnt aware that I was breaking the charter? Posted pseudo-code? Asked questions, not for homework, its a website Im working on and have exhausted other avenues..

    Thanks for the attempt though Webmonkey, have tried it and tis giving me "Subquery returns more than one row" error. And Im trying to tell the compiler "Well, hell yeah! Thats what its supposed to do?" but its not listening to me..

    Oh well, back to google.
    Nah wasn't saying your thread was rule breaking, just that If i gave full solution it may be bad for me.

    Well you got it working anyways. Cool :)


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,127 ✭✭✭smcelhinney


    ta Phil, and webmonkey, for pointing me in the right direction..


  • Registered Users, Registered Users 2 Posts: 1,712 ✭✭✭neil_hosey


    Been wracking my brains (and Googles!) for the past little while on this. Can someone transcribe the following pseudocode to SQL for me (Im using MySQL version 5.0.27).
    for each item in (select product_id AS id from products where manu_id = x)
    do
         update descriptions set url = y where products_id = $id (from above)
    done
    

    make sense?

    update DESCRIPTIONS
    set URL = Y
    where PRODUCT_ID in (select PRODUCT_ID from PRODUCTS where MANU_ID = X)

    ah i see someone done it already. :(


Advertisement