mysql fastest queries

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
pedroz
Forum Commoner
Posts: 99
Joined: Thu Nov 03, 2005 6:21 am

mysql fastest queries

Post by pedroz »

[not sure if this the correct category to post]

although there are some solutions for this...
what is, in your opinion, the fastest queries for this?...

C1 | C2 | C3 | C4
------------------
AA | BB | XX | XX
A1 | B1 | 12 | 34
A2 | B2 | XX | XX

When C3 and C4 = XX, UPDATE C3 = C1 AND C4 = C2

C1 | C2 | C3 | C4
------------------
AA | BB | AA | BB
A1 | B1 | 12 | 34
A2 | B2 | A2 | B2
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: mysql fastest queries

Post by John Cartwright »

Fastest queries? Compared to what?

I would just do

[text]UPDATE mytable SET c3 = c1, c4 = c2 WHERE c3 = 'XX' AND c4 = 'XX'[/text]

Moved to Databases.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: mysql fastest queries

Post by Darhazer »

use "explain " to see how your query is executed.
You can create index on C3 and C4 (one index on both fields) to speed up the lookup. You have to test if this will give you better results in terms of performance
Post Reply