I have a table MyTable
with these columns:
MyTableId: int
Results: varchar(200)
And I have another table called Users
:
UserId: int
Username: varchar(200)
MyTableId: int
I am cleaning up MyTable
and I have a bunch of results that are now saying 'Bad Data'. I want to get a list of all the MyTableIds that have 'Bad Data' as their result and see if they are any of those Id's in the User
table.
I am open to any suggestions about this.
A sample data is like so:
MyTable
MyTableId (PK) Results
1 The quick fox is fast
2 Bad Data - another piece of very bad data
3 Humpty dumpty sits on the wall
4 Hello this is a sample
5 Bad Data - this data is bad
Users
UserId (PK) Username MyTableId (FK)
1 User1 1
2 User2 2
3 User3 3
4 User4 1
5 User5 5
6 User6 2
So essentially I need to delete the bad data in MyTable with something like so:
DELETEROM MyTable WHERE Results LIKE 'Bad Data%';
This won't work because I need a script that deletes the FK data first in the Users table. I need it to be dynamic as this is just sample data.