Results 1 to 9 of 9
Code:
UPDATE product,
SET
so what i need to do is here is an if command "IF price > 75 THEN price = price *1.20 END IF But i cant ...
- 10-08-2010 #1Linux Newbie
- Join Date
- May 2009
- Location
- Kitchener, Ontario, Canada
- Posts
- 187
SQL Oracle Help
so what i need to do is here is an if command "IF price > 75 THEN price = price *1.20 END IF But i cant seem to get the right syntax :SCode:UPDATE product, SET
Code:WHERE vendor_id IN (SELECT product_id, vendor_id, price FROM product WHERE vendor_id IN (SELECT vendor_id FROM vendor WHERE name = 'SyQuest Technology')) ROLLBACK;Last edited by donaldfarkas; 10-08-2010 at 08:05 PM. Reason: wrong title
- 10-09-2010 #2
hi
it can be done without if then else,
update p..
set price=price*1.2
where price >75
and vendor_id in ?
try it if u deem it necessary..Take risks: if you win, you will be happy; if you lose, you will be wise.
New Users : Read This First
- 10-09-2010 #3Linux Newbie
- Join Date
- May 2009
- Location
- Kitchener, Ontario, Canada
- Posts
- 187
- 10-10-2010 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
In theory, the optimizer should create the same plan for both statements, but not necessarily, so the second may be better in that it will perform the vendor_id restriction first (once) instead of each time it finds a candidate entry where the price > 75. If you are using Oracle, you can ask it to "explain plan" for each and compare the cost of each version of the query.Code:update product set price=price*1.20 where price>75 and vendor_id in (select vendor_id from vendor where name = 'SyQuest Technology'); or update product set price=price*1.20 where vendor_id in (select vendor_id from vendor where name = 'SyQuest Technology') and price>75;Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 10-11-2010 #5
i would use the update join syntax:
Code:update product as p inner join vendor v using(vendor_id) set price = price * 1.2 where v.name = 'SyQuest Technology' and price > 75
- 10-11-2010 #6Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
That may works too, though the syntax isn't supported by all SQL implementations. I think this will work more universally:
Again, since I haven't tried this, not all implementations may support it; however, my first example should work on all known SQL implementations. Anyway, he can try them all manually and assuming his implementation supports transactional boundaries, just rollback after trying each one.Code:update product p, vendor v set p.price = p.price * 1.2 where p.vendor_id = v.vendor_id and v.name = 'SyQuest Technology' and p.price > 75;
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 10-11-2010 #7Linux Newbie
- Join Date
- May 2009
- Location
- Kitchener, Ontario, Canada
- Posts
- 187
Thank you guys for all your input ill give it a try on tuesday and let you know how i did it
- 10-11-2010 #8
i think first you have to try it then discuses .
Take risks: if you win, you will be happy; if you lose, you will be wise.
New Users : Read This First
- 10-11-2010 #9Linux Newbie
- Join Date
- May 2009
- Location
- Kitchener, Ontario, Canada
- Posts
- 187


Reply With Quote
