0

I want to get the value of the where statement in a query.

For example:

UPDATE tablename SET name = 'test' WHERE lastname = 'doo'

I want query to return me 'doo'. Is there any sql solution for it ?

Hcorg
  • 11,598
  • 3
  • 31
  • 36
Tupic
  • 545
  • 1
  • 6
  • 12

2 Answers2

0

I'm not sure if you really need this, but you have to use SELECT instead of UPDATE if you want to select any values, in following:

SELECT lastname
FROM tablename
WHERE name = 'test'

In this case you will select lastname where name is 'test'

0

You can use SELECT query with UPDATE query for that :

UPDATE tablename SET name = 'test' WHERE lastname = 'doo';select lastname from tablename where lastname = 'doo';

Above query will return lastname.

I don't know about other DataBase but for MS SQL Server you can use directly like this(may be it's not good but will work)

UPDATE tablename SET name = 'test' WHERE lastname = 'doo';select 'doo' as lastname;

it will result the same as first query.

BhushanK
  • 1,205
  • 6
  • 23
  • 39