Devon
Devon

Reputation: 335

Athena SQL query issue

I'm trying to get the data from each value... It works fine with only one AND url LIKE '%value%', but I'm missing something to be able to do multple values, please let me know

SELECT count(*)
FROM "access_logs"
WHERE year = '2018'
    AND month = '2'
    AND day = '22'
    OR url LIKE '%value%'
    OR url LIKE '%value%'
    OR url LIKE '%value%'
    OR url LIKE '%value%'
    OR url LIKE '%value%'
    OR url LIKE '%value%'
group by url

Upvotes: 1

Views: 1130

Answers (2)

David Breen
David Breen

Reputation: 247

It seems like you should have all of the OR's in brackets like so:

SELECT COUNT(*)
FROM "access_logs"
WHERE year = '2018'
AND month = '2'
AND day = '22'
AND (url LIKE '%value%'
    OR url LIKE '%value%'
    OR url LIKE '%value%'
    OR url LIKE '%value%'
    OR url LIKE '%value%'
    OR url LIKE '%value%')
GROUP BY url

Upvotes: 1

Eric
Eric

Reputation: 3257

You need bracket around OR

SELECT count(*)
FROM "access_logs"
WHERE year = '2018'
    AND month = '2'
    AND day = '22'
    AND (url LIKE '%value%'
    OR url LIKE '%value%'
    OR url LIKE '%value%'
    OR url LIKE '%value%'
    OR url LIKE '%value%'
    OR url LIKE '%value%')
group by url

Upvotes: 2

Related Questions