Trying to fix case:
UPDATE users SET state = 'DC' AND city = 'Washington' WHERE state = 'DC' AND city = 'Washington'
AND
with a comma and everything should be okay. Like so:UPDATE users
SET state = 'DC', city = 'Washington'
WHERE state = 'DC'
AND city = 'Washington'
Re:Just making it a bit clearer than the first rep
vsergu on 2003-12-01T21:13:09
You got it. I noticed there was a problem (caused by copy-and-paste) when I saw how many rows were updated. Fortunately it was easy enough to fix the rows that now had a state of '0'.Re:Just making it a bit clearer than the first rep
Wallie on 2003-12-02T12:03:08
AFAIK nothing will change when you execute this query. The values in the WHERE en in the SET parts are equal so it will only update rows where the case is already corect.
You might want to do something with TO_LOWER() (in case of Oracle) in the WHERE clause. This will cause any indexes on the STATE and CITY column to be ignored (unless you used function-based indexes ).
UPDATE users
SET state = 'DC', city = 'Washington'
WHERE TO_LOWER(state) = 'dc'
AND TO_LOWER(city) = 'washington'
markRe:Just making it a bit clearer than the first rep
vsergu on 2003-12-02T13:54:46
I'm using MySQL, so the comparisons are case-insensitive (it depends on how the columns are defined). The query worked fine once I'd fixed the "AND" problem.Re:Just making it a bit clearer than the first rep
Wallie on 2003-12-02T14:16:18
I didn't know that. It's been a while since I looked at MySQL. I'm waiting for a stable release that supports subqueries, at that point I'm going to look at it more closely.
I'm not sure if I like the idea of case-insensitive columns (especially for names). But that's my personal opinion and it's configurable so I can always turn case-sensitivity on:-)
mark
which returned rather few results.SELECT *
FROM records
WHERE city='Los Angeles'
AND city='New York'
Re:That reminds me...
hex on 2003-12-02T12:54:23
That pesky English language. I guess in pseudocode that would beI'm an SQL newbie, though, so maybe there is some kind of do-multiple-selects-at-once (intersecting selects?) syntax that I'm not familiar with.SELECT *
FROM records
WHERE city='Los Angeles'
AND ALSO SELECT *
FROM records
WHERE city='Los Angeles'Re:That reminds me...
Wallie on 2003-12-02T14:09:51
How about:
This works if your RDBMS supports UNION queries. AFAIK MySQL does this since 4.0.0.SELECT *
FROM records
WHERE city='Los Angeles'
UNION ALL
SELECT *
FROM records
WHERE city='New York'
In this example I would not use this method. Thecity = 'New York' or city = 'Los Angeles'
is much better.
markRe:That reminds me...
hex on 2003-12-02T14:17:56
Yeah, it is, and clearer as well. Interesting to know, though.