I am starting out in SQL and am trying to do a query that will select all event names that are unique and do not have ‘TODAY-XXXXXXXX’ in the value for the event_name column. I have a query that works fine for getting the unique values from the table, but I cannot get the NOT LIKE to work well.
For example, I was to remove all items that have this as their name TODAY-20191021 the data at the end can change but all have the TODAY in front of the date
This is the query that is working fine
SELECT DISTINCT event_name, COUNT(*) FROM events GROUP BY event_name Having COUNT(*) > 100.
But when I try to add the where clause it fails with this error
Error running query: column “TODAY-%” does not exist LINE 3: WHERE event_name NOT LIKE “TODAY-%” ^
This is what I have so far
SELECT DISTINCT event_name, COUNT(*) FROM events WHERE event_name NOT LIKE "TODAY%" GROUP BY event_name Having COUNT(*) > 100.
Advertisement
Answer
Here:
WHERE event_name NOT LIKE "TODAY%"
Because you use double quotes, the database considers this string as an identifier (here, a column name). Instead, you want to use single quotes, that stand for literal strings:
WHERE event_name NOT LIKE 'TODAY%'