# AND & OR with mySQL

**URL:** <https://forum.kirupa.com/t/and-or-with-mysql/288100>\
**Category:** programming\
**Created:** [May 11, 2009, 11:04am UTC](https://forum.kirupa.com/t/and-or-with-mysql/288100 "2009-05-11T11:04:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nburlington](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nburlington/32/1365_2.png) [@nburlington](https://forum.kirupa.com/u/nburlington)\
**Post date:** [May 11, 2009, 11:04am UTC](https://forum.kirupa.com/t/and-or-with-mysql/288100/1 "2009-05-11T11:04:11Z")

</div>

I want to check the logic on this query. If I write:

SELECT user.id FROM users WHERE user.firstname = ‘John’ AND user.lastname = ‘Doe’ OR user.lastname = ‘Smith’

Does the AND/OR relationship work like IF/ELSE? Can I assume that my OR condition will be linked to the AND that directly precedes it? In this case (Doe or Smith).

I want to make sure that the logic is grouping like this:

[AND x] && [y OR z]

not

[AND x AND y] || z
