mardi 30 juin 2015

SQLite: Can I have a where statement inside another where statement?

I am writing SQL queries in Ruby on Rails application and I will execute these statements in SQLite data base.

Because my queries are composed by other complicated statements, I thought that I can include a where statement inside another where statement.

for example:

SELECT * FROM "patients" INNER JOIN "encounters" INNER JOIN "conditions" WHERE "patients"."patient_characteristic_birthdate" <= '1997-06-30 07:25:50 UTC' AND "encounters"."length_of_stay" <= 120 AND "encounters"."encounter" = 'Inpatient Encounter' AND (SELECT * FROM "patients" INNER JOIN "conditions" WHERE ("conditions"."diagnosis" = 'cancer' OR "conditions"."diagnosis" = 'obesity')))

For this statement, I have the following error: ActiveRecord::StatementInvalid (SQLite3::SQLException: only a single result allowed for a SELECT that is part of an expression:

Aucun commentaire:

Enregistrer un commentaire