Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table named poa and 8 fields, and 2 of these fields are year2 and proyecto.
I want to delete data based on those 2 fields, so that when I select a project in my website and then a year, let's say 2017, the rows that match these 2 filds will get deleted.
Can someone please help me?
Thanks.

What I have tried:

delete from poa where year2 like '2017' and proyecto like 'proy1';
Posted
Updated 7-Dec-17 8:09am
Comments
[no name] 7-Dec-17 13:57pm    
And what is the Problem?
What I see is you are using LIKE without a Joker character.

Finally your SQL is equal to delete from poa where year2 = '2017' and proyecto = 'proy1';

Most probably that is your Problem.
Member 10850253 7-Dec-17 14:12pm    
I also tried that, and it didn't work. If you have any other suggestions, please let me know.
Thanks.
[no name] 7-Dec-17 14:16pm    
What you tried exactly?
Something like delete from poa where year2 = '2017' and proyecto = '*proy1*';

Anyway, describe more exactly what your are doing, what you expect and what you get.

[Edit]
BTW it Looks like mySQL's Joker character seems to be '%' and _not_ '*'
Member 10850253 7-Dec-17 14:35pm    
Exactly that, but without the joker character.
[no name] 7-Dec-17 14:36pm    
Does a record exists which mach your criterions?

1 solution

LIKE is not a good choice here: it's generally used for strings, and a YEAR column should be an integer, not a string.
And LIKE is only really useful when you give it a wildcard specification, similar to "*.jpg" in Windows will return all JPEG files in a folder.
For MySQL and SQL Server, the primary wildcard is the '%' character which matches anything in the same ways the '*' dowes in Windows.

If you don't need wildcards, don't use LIKE; use '=' instead:
SQL
DELETE FROM poa WHERE year2 = 2017 AND proyecto = 'proy1';
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900