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

SQL Help please?

Options
  • 18-12-2007 11:33am
    #1
    Registered Users 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 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 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 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 Posts: 7,468 ✭✭✭Evil Phil


    This thread is certified charter breakingness free :)


  • Registered Users 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 Posts: 1,127 ✭✭✭smcelhinney


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


  • Registered Users 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