homepage Welcome to WebmasterWorld Guest from 54.197.65.82
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
Join SELECT an UPDATE?
l008comm

10+ Year Member



 
Msg#: 4225593 posted 7:02 pm on Nov 2, 2010 (gmt 0)

My site has a simple counter. there are two queries that run back to back. Is there any way to join these into one query? Even if it just reduced the number of database connections, this page gets loaded a lot, any little optimization will be magnified a lot.

1)
UPDATE `counter` SET main_counter = main_counter + 1

2)
SELECT `main_counter` FROM `counter`

 

Demaestro

WebmasterWorld Senior Member demaestro us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4225593 posted 8:55 pm on Nov 2, 2010 (gmt 0)

You can do it in a transaction...

the syntax depends on what db/version you are using.

Check the user guide of your db for TRANSACTION

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved