Working with multiple tables 25
For real data, we would need to go through these records and find out why, fixing those that
can be fixed. Once we do fix it, we could get rid of the album column in the newSongs
table.
One other thing to fix in newSongs is the ID column: it was not transferred over as auto
increment. So go ahead and switch the ID column to auto increment.
First, it tells you invalid default value for ID . Switch Null to YES and the default value
to NULL. Then, you'll get a different error.
Try the following:
select * from newSongs where id=7185
This is the Time Warp from the Rocky Horror Picture Show. It's in there twice. How many
items do we have like this?
select id, artist, song, album, count(*) as idCount from newSongs group by id
having idCount > 1
Having is a form of where that often works better after group by. If you can use where,
however, it is almost always a better choice.
Looks like we have 61 songs that ended up getting duplicated. Why?