# Can you spot the SQL syntax error?

**URL:** <https://www.ruby-forum.com/t/can-you-spot-the-sql-syntax-error/113418>\
**Category:** Rails\
**Created:** [August 30, 2007, 10:33pm UTC](https://www.ruby-forum.com/t/can-you-spot-the-sql-syntax-error/113418 "2007-08-30T22:33:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![LAB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ba8739/32.png) [@LAB](https://www.ruby-forum.com/u/LAB)\
**Post date:** [August 30, 2007, 10:33pm UTC](https://www.ruby-forum.com/t/can-you-spot-the-sql-syntax-error/113418/1 "2007-08-30T22:33:51Z")

</div>

In my controller neighborMatches I have an array of ids:

neighborMatches = neighborMatches.map!{|n| n.id}

I want to find all the properties that match some conditions, and is  
also in this list of ids:

@properties = Property.find(:all, :conditions =\> ["(NO\_BEDROOMS \> ?  
AND NO\_FULL\_BATHS \> ? AND SQUARE\_FEET \> ? AND LIST\_PRICE \> ? AND  
LIST\_PRICE \< ? AND id IN ?)", beds, baths, sqft, priceLow, priceHigh,  
neighborMatches]

I get an invalid SQL error: Mysql::Error: #42000You have an error in  
your SQL syntax; check the manual that corresponds to your MySQL  
server version for the right syntax to use near  
‘3,33,41,187,432,497,533,537,558,561,564,245,274,365,474,534,536,577,4,18,235,346’  
at line 1: SELECT \* FROM properties WHERE ((NO\_BEDROOMS \> ‘1’ AND  
NO\_FULL\_BATHS \> ‘1’ AND SQUARE\_FEET \> ‘500’ AND LIST\_PRICE \> ‘0’ AND  
LIST\_PRICE \< ‘99999999’ AND id IN  
3,33,41,187,432,497,533,537,558,561,564,245,274,365,474,534,536,577,4,18,235,346,396,439,509,66,468))

Can anyone spot the SQL syntax error? Thanks in advance!!

LAB

---

<div class="post-metadata">

**Author:** ![LAB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ba8739/32.png) [@LAB](https://www.ruby-forum.com/u/LAB)\
**Post date:** [August 30, 2007, 10:50pm UTC](https://www.ruby-forum.com/t/can-you-spot-the-sql-syntax-error/113418/2 "2007-08-30T22:50:53Z")

</div>

I believe the IN clause needs parentheses:

AND id IN  
(3,33,41,187)

Tiago M.

---

<div class="post-metadata">

**Author:** ![LAB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ba8739/32.png) [@LAB](https://www.ruby-forum.com/u/LAB)\
**Post date:** [August 30, 2007, 10:50pm UTC](https://www.ruby-forum.com/t/can-you-spot-the-sql-syntax-error/113418/3 "2007-08-30T22:50:53Z")

</div>

IN (value1/,/value2,…)

---

<div class="post-metadata">

**Author:** ![LAB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ba8739/32.png) [@LAB](https://www.ruby-forum.com/u/LAB)\
**Post date:** [August 30, 2007, 10:58pm UTC](https://www.ruby-forum.com/t/can-you-spot-the-sql-syntax-error/113418/4 "2007-08-30T22:58:53Z")

</div>

cool … that was it!! Thank you!!

…AND id IN (?)
