-1

I try to select all rows with ruby where the field is null. Either I get zero results or the statement is invalid. So far I tried:

db.query("SELECT * FROM names where name is null;")
db.query("SELECT * FROM names where name is nil;")
db.query("SELECT * FROM names where name is #{null};")
db.query("SELECT * FROM names where name is #{nil};")

How should the select statement be?

i use ruby and mysql2 gem

user2211703
  • 489
  • 2
  • 5
  • 14
  • 1
    Replace `#select_stmt` with `#query` .. like `db.query("SELECT * FROM names where name is null;")` – Arup Rakshit Jul 31 '14 at 12:58
  • i forget to say i use ruby and the mysql2 gem. select_stmt should be query. update: "Select * from names where names is null;" worked suddenly – user2211703 Jul 31 '14 at 13:08
  • We can see that from the tags - http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles – Uri Agassi Jul 31 '14 at 13:22
  • The first statement is correct. Have you tried that same statement in the MySQL prompt to see if you get a different result? – Max Jul 31 '14 at 13:55

1 Answers1

0

SELECT * from 'names' WHERE 'name' IS NULL

This is what works in plain MySQL, seeing now that you use ruby this might not help you.

Bob Gilmore
  • 12,608
  • 13
  • 46
  • 53
Nico
  • 13
  • 4