This Count is from vehicle table
But It don’t work…
Do you agree with me:
If I have
Vehicle1
Vehicle2
Vehicle3
Vehicle4
Vehicle5
And If I make query good(That delete all ID which are not on any of this slots(vehicle1,vehicle2…) that I can’t have more than 5 vehicles? There is problem,after query;i have 8 vehicles.
After your query: SELECT ID FROM vehicle WHERE name = 'PaulC' Result:
ID
15
190
378
21
22
99
110
126
SELECT Vehicel1,Vehicel2,Vehicel3,Vehicel4,Vehicle5 FROM users WHERE name = 'Paul_Castellano'
Result:
Vehicle1: 22
Vehicle2: 99
Vehicle3 : 110
Vehicle4: 126
Vehicle5: 0(I don’t have Vehicle5)
So…
ID 15,190,378,21 are not on any slot(vehicle1,vehicle2…) and they are not deleted…I don’t know why.
EDIT:
"You did not say you wanted to delete vehicle IDs for a specify user. "
I want to delete for all users.I’m just use my account for examples!
When you ran the SQL code I gave you earlier, did it not show an error? I noticed you had a capital V instead of a lowercase v for the 5 fields in users. I have corrected my original query to be a capital V for each field name, so this should work. I recreated the following tables:
users table
userID
Vehicle1
Vehicle2
Vehicle3
Vehicle4
Vehicle5
1
22
99
110
126
0
vehicle table
ID
15
190
378
21
22
99
110
126
After the following SQL exectutes, IDs 15, 190, 378, 21 will be deleted from the vehicle table, leaving only IDs 22, 99, 110, 126
DELETE FROM vehicle where ID NOT IN (
SELECT DISTINCT Vehicle1 FROM users
UNION SELECT Vehicle2 FROM users
UNION SELECT Vehicle3 FROM users
UNION SELECT Vehicle4 FROM users
UNION SELECT Vehicle5 FROM users
);
I’m so sorry!
It’s my bad.
Now I’m check and ID: 15,190,378,21 have on another user account(This is my test database so…Some things are mixed…)
Sorry for your time,I’m also lost my day with this…Query is good and it will work on my main database.