tags:

views:

285

answers:

1

Hi, i've got two queries first:

SELECT
    players.username AS username,
    tmp_player_operations.id AS tmp_id, 
    tmp_player_operations.operation_type AS operation_type, 
    tmp_player_operations.veryfication_code AS veryfication_code, 
    tmp_player_operations.expiration_date AS expiration_date,
    tmp_player_operations.used AS used
FROM
    players LEFT OUTER JOIN tmp_player_operations 
    ON players.id = tmp_player_operations.player_id
WHERE
tmp_player_operations.veryfication_code = '3c3c4375086fbcbc1cef938a0bfabbb9'

second:

UPDATE 
    players LEFT JOIN tmp_player_operations 
    ON players.id = tmp_player_operations.player_id
SET 
    tmp_player_operations.used = 1,
    players.active = 1
WHERE
    tmp_player_operations.id = 8

Now i would like to make this update inside select, i mean something like:

(CASE
   WHEN
      tmp_player_operations.used = 0
      THEN
          UPDATE....
          AND 'updated'
   ELSE
      'not updated'
END) AS something

is something like this possible?

+1  A: 

No, it's not possible. A query can be either a SELECT or an UPDATE, but not both.

You could, I suppose, use a stored procedure to make one database call to do both the update and the select, but that'd still really be two queries (but that application would only see one, the stored proc call). Chapter 18 of the MySQL manual has details on stored procedures.

Perhaps you should back up a bit, and ask us how to accomplish whatever your actual goal is?

derobert
I'll make it with stored proc, i only wanted to know if it is possible, so your answer helped me. I just wanted to make one mysql connection instead of two.
Cfaniak
You can issue multiple queries per connection, not sure why you'd need two connections.
derobert