Say for example you had a CD Database, where you wanted to increase the CD prices of all CD’s with the genre ‘Pop’ by 10%. However the type Genre is a SET. Where it can be in multiple genre’s, such as RnB and Rock.
My code is as follows:
UPDATE CD
set price = price * 1.1
WHERE genre = 'Pop';
However my code is only updating rows where the Genre is ONLY pop. If the Genre is ‘Rock,Pop,RnB’, it is not updated. What am i doing wrong?
You need to use
LIKE(Documentation):This will match if your genre is “Rock,Pop,RnB.”
You should be aware that you are using a non-normalized structure. A better design would be to have a genre reference table:
CD_Genre (CD, Genre)