# Sql - using AND OR

**URL:** <https://forum.kirupa.com/t/sql-using-and-or/216772>\
**Category:** Uncategorized\
**Created:** [February 20, 2007, 1:47pm UTC](https://forum.kirupa.com/t/sql-using-and-or/216772 "2007-02-20T13:47:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zaid\_W1red](https://avatars.discourse-cdn.com/v4/letter/z/cab0a1/32.png) [@Zaid\_W1red](https://forum.kirupa.com/u/Zaid_W1red)\
**Post date:** [February 20, 2007, 1:47pm UTC](https://forum.kirupa.com/t/sql-using-and-or/216772/1 "2007-02-20T13:47:14Z")

</div>

Hey guys,

So I have this SQL select statement:

SELECT \*, SUM(downloads) AS totaldownloads FROM stats WHERE day LIKE ‘20’ AND month LIKE ‘02’ AND year LIKE ‘2007’ AND name LIKE ‘%test%’ AND type = ‘text’ GROUP BY name

And I want to basically modify the statement so that as well as matching my name column, a column called ‘path’ also matches.

If I do this:

SELECT \*, SUM(downloads) AS totaldownloads FROM stats WHERE day LIKE ‘20’ AND month LIKE ‘02’ AND year LIKE ‘2007’ AND name LIKE ‘%test%’ **OR path = ‘%path%’** AND type = ‘text’ GROUP BY name

Is it separating the statement into two conditions? In the below the bold section is what I see as possibly being statement B, non bold statement A.

SELECT \*, SUM(downloads) AS totaldownloads FROM stats WHERE day LIKE ‘20’ AND month LIKE ‘02’ AND year LIKE ‘2007’ AND name LIKE ‘%test%’ **OR path = ‘%path%’ AND type = ‘text’** GROUP BY name

If that’s the case what’s the correct syntax??

If this doesn’t make sense…someone pipe up an d let me know!
