OR in WHERE

Andrew Sinning andrew at learningware.com
Mon May 17 12:27:02 CDT 2004


I think that I've read that this is broken, but I'm just not smart
enough to think of another way to write this sql statement.  Perhaps
with a little help I'll catch on.

I have two tables 'questions' and 'infos'.

questions.infoId
and
questions.introId

can either be related to infos.iId

I want to find all the info that correspond to either an infoId OR an
introId in questions

-- looking for JUST the infoId's, works just fine:
sql = "SELECT iId FROM infos, questions WHERE questions.infoId =
infos.iId"
put dbQuery(sql)
-- [[#iID: 98], [#iID: 101], [#iID: 94], [#iID: 73], [#iID: 74], [#iID:
75], [#iID: 76], [#iID: 77], [#iID: 78], [#iID: 79], [#iID: 80], [#iID:
81], [#iID: 82], [#iID: 83], [#iID: 84], [#iID: 85], [#iID: 86], [#iID:
87], [#iID: 88], [#iID: 89], [#iID: 90], [#iID: 91], [#iID: 92]]

-- looking for JUST the introId's, works just fine:
sql = "SELECT iId FROM infos, questions WHERE questions.introId =
infos.iId"
put dbQuery(sql)
-- [[#iID: 96], [#iID: 99], [#iID: 93]]


BUT, now I need to combine the two, and I get no result:
sql = "SELECT iId FROM infos, questions WHERE (questions.infoId =
infos.iId) OR (questions.introId = infos.iId)"
put dbQuery(sql)
-- []




More information about the Valentina mailing list