lbillett Posted December 16, 2009 Share Posted December 16, 2009 Hello Freaks! First time poster, long time reader. I'm making a simple standalone blog extension in mediawiki for work and am getting KILLED trying to use the IN() condition. Fighting with it recently actually made me realize I've never actually gotten one work before. EVER! I usually end up using a loop to build an outrageous looking bunch of OR's into a query string to get around it. This madness has to stop. I've done everything I can think of to tweak the syntax. I still get query errors. Can anyone see what I'm doing wrong? From what I can see, I'm following the usage perfectly! I have a table called simpleblog_perms looking something like this: id (INT) group (TEXT) logid (INT) perm (TEXT) --------- --------------- ------------ ------ 1 Staff 1 R 2 sysop 1 W The following queries all result in an error! SELECT * FROM simpleblog_perms WHERE group IN (Staff,bureaucrat,sysop) SELECT * FROM simpleblog_perms WHERE group IN (Staff, bureaucrat, sysop) SELECT * FROM simpleblog_perms WHERE group IN ('Staff','bureaucrat','sysop') SELECT * FROM simpleblog_perms WHERE group IN ('Staff', 'bureaucrat', 'sysop') SELECT * FROM simpleblog_perms WHERE (group IN ('Staff','bureaucrat','sysop')) They each return something like MySQL returned error "1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group IN ('Staff','bureaucrat','sysop')' at line 2 (localhost)". I'm using MySQL 5.1.30 with PHP 5.2.9-2 Quote Link to comment https://forums.phpfreaks.com/topic/185365-select-where-in/ Share on other sites More sharing options...
rajivgonsalves Posted December 16, 2009 Share Posted December 16, 2009 group is a mysql reserved keyword quote it in backticks ` SELECT * FROM simpleblog_perms WHERE `group` IN ('Staff','bureaucrat','sysop') Quote Link to comment https://forums.phpfreaks.com/topic/185365-select-where-in/#findComment-978531 Share on other sites More sharing options...
lbillett Posted December 16, 2009 Author Share Posted December 16, 2009 Worked first try. There are literally wave's of ecstasy are rolling over me. Wow, how lame am I? Thank you tons. Quote Link to comment https://forums.phpfreaks.com/topic/185365-select-where-in/#findComment-978543 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.