Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - SQL query problem - WHERE / OR / AND
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

SQL query problem - WHERE / OR / AND

 Post Reply Post Reply
Author
pedalcars View Drop Down
Senior Member
Senior Member


Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
Post Options Post Options   Thanks (0) Thanks(0)   Quote pedalcars Quote  Post ReplyReply Direct Link To This Post Topic: SQL query problem - WHERE / OR / AND
    Posted: 21 May 2003 at 3:31am
I've hit a SQL query problem (Access database).

In a table, entries can be one of about half a dozen different types; additionally (regardless of type) there is a true/false entry.

I want to bring out entries of three types only, but ONLY those for which the true/false is also true.

Currently I have a statement in the form:

strSQL = "SELECT tblTable.* FROM tblTable WHERE tblTable.Type = 'type1' OR tblTable.Type = 'type2' OR tblTable.Type = 'type3' AND tblTable.TrueFalse = True;"

Unfortunately, this seems to bring back ALL 'type1' records, ALL 'type2' records, and 'type3' records which are also "True"; in psuedo-mathematical notation it's doing:

type1 OR type2 OR (type3 AND True)

When I want:

(type1 OR type2 OR type3) AND True

i.e., I want it to find all type1, 2 and 3 records which are True; it's only applying the True/False criteria to the last selected type. I need to force the statement to consider each "OR" first, and then consider the "AND" section.

Help!



PS. I've tried putting the True/False criteria first, then AND...type1 OR...type2 OR type3, it makes no difference beyond doing "(True AND Type1) OR type2 OR type3"

PPS. I don't really want to duplicate the "AND" section after each or the Type selection sections, mainly because it looks ugly and there must be a neater way!

Ta

Edited by pedalcars
www.pedalcars.info

The most fun on four wheels

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 21 May 2003 at 6:21am

When I want:

(type1 OR type2 OR type3) AND True

 

So use that notation.. stuff inside ()'s get evaluated first

Contribute to the working anarchy we fondly call the Internet
Back to Top
pedalcars View Drop Down
Senior Member
Senior Member


Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
Post Options Post Options   Thanks (0) Thanks(0)   Quote pedalcars Quote  Post ReplyReply Direct Link To This Post Posted: 21 May 2003 at 6:29am
Hey cool, something else I never knew / hadn't read about ASP!

So simple when you know how...

Thanks MorningZ, yet another of my ASP problems you've solved!
www.pedalcars.info

The most fun on four wheels

Back to Top
Bunce View Drop Down
Senior Member
Senior Member
Avatar

Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bunce Quote  Post ReplyReply Direct Link To This Post Posted: 21 May 2003 at 6:42am

There's also the IN() keyword:

WHERE tblTable.Type IN ('Type1','Type2','Type3') 

Cheers,
Andrew 

 

There have been many, many posts made throughout the world...
This was one of them.
Back to Top
pedalcars View Drop Down
Senior Member
Senior Member


Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
Post Options Post Options   Thanks (0) Thanks(0)   Quote pedalcars Quote  Post ReplyReply Direct Link To This Post Posted: 22 May 2003 at 5:43am
Thanks Bunce - even neater!

www.pedalcars.info

The most fun on four wheels

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.