Forums

This topic is locked

Advanced recordset using OR

Posted 14 Jan 2008 16:28:38
1
has voted
14 Jan 2008 16:28:38 Mike V posted:
I have the following simple recordset that works fine...

SELECT *
FROM CLBcontact
WHERE CLBlink1 = colname
ORDER BY CLBname ASC

The next step is adding CLBlink2 in the Where statement so that both columns in the table get searched by the colname variable. Used the OR function like this...

SELECT *
FROM CLBcontact
WHERE CLBlink1 OR CLBlink2 = colname
ORDER BY CLBname ASC

...and resulted all items in the table.

Added ( ) in the Where statement like this...

SELECT *
FROM CLBcontact
WHERE (CLBlink1 OR CLBlink2) = colname
ORDER BY CLBname ASC

...and resultrd no items from the table.

What I'm trying to do is send a url variable to a recordset with multiple columns and want only the matching rows returned. Currently the results have only been all or none using the above sql.

Greatly appreciate the help!

Mike

Replies

Replied 14 Jan 2008 20:15:50
14 Jan 2008 20:15:50 Alan C replied:
HI
I think you have to be quite specific about the where clause and write it out like . . .

SELECT *
FROM CLBcontact
WHERE CLBlink1 = colname OR CLBlink2 = colname
ORDER BY CLBname ASC

so you show the conditions more fully, it's a while since I wrote one like that but what you can try (if you have phpmyadmin) is to use that and type in your sql and execute it, then modify the query and see how it reacts

Hope that helps
Replied 14 Jan 2008 21:24:40
14 Jan 2008 21:24:40 Mike V replied:
Hi Alan,

Having two variables named "colname" didn't work. So I created a new "colname2" variable and kept the same url variable name from the sending page and that worked. Pretty cool, sorta like multi-tasking! Appears that each variable has to be specific as you stated.

Thanks for the help.

Mike
Replied 15 Jan 2008 11:02:15
15 Jan 2008 11:02:15 Alan C replied:
great stuff Mike,

glad to hear it's going

Reply to this topic