Richard Richard - 1 year ago 60
SQL Question

SQL query - making change to multiple result

I'm still very new to this so forgive me. I'm normally a 2nd deskside support engineer for general PC issues, but due to being out of work thought I would try and expand my skillset.

I have a statement:

SELECT * FROM `TABLE 1` WHERE `Colour` LIKE 'Red' AND `Location` LIKE 'London-My'


This returns a handful of results.

How do I then change these results say to change the value of (for example) Location: London-My to a new location(Say London Docklands)?

Sorry to ask, I can find how to change multiple values but not from a multi value result as above.

Answer Source

It's not quite clear what you meant by "change multiple values", but

if you wanted to actually update the data:

UPDATE `TABLE 1` 
   SET `Location` = 'London Docklands'
 WHERE `Colour` LIKE 'Red' 
   AND `Location` LIKE 'London-My'

if you just needed to change the values in the returned resultset:

SELECT 'London Docklands' AS `Location`,
       `Colour`
       -- other needed columns go here
  FROM `TABLE 1` 
 WHERE `Colour` LIKE 'Red' 
   AND `Location` LIKE 'London-My'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download