473,598 Members | 3,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to query the same table for more than one possible results

229 New Member
Hi,
I wonder if anyone can tell me how to write this query properly as this one doesnt work.

where tbl.gallery='Ab stract' and tbl.gallery='Ab stract art'

Need to query the same table for the results that match the two possible results.

Thanks in advance
Richard
Aug 17 '10 #1
4 1491
Jerry Winston
145 Recognized Expert New Member
This is kind of a data questions. I think the syntax you're looking for is OR.

Expand|Select|Wrap|Line Numbers
  1. tbl.gallery='Abstract' OR tbl.gallery='Abstract art'
Aug 18 '10 #2
jhardman
3,406 Recognized Expert Specialist
alternatively,
Expand|Select|Wrap|Line Numbers
  1. tbl.gallery in ('Abstract','Abstract art','Modern art')
Jared
Aug 25 '10 #3
NeoPa
32,566 Recognized Expert Moderator MVP
What you have to understand Richard, is that an AND in the WHERE clause is not saying :
Expand|Select|Wrap|Line Numbers
  1. Get me :
  2. All records where {first check}
  3. AS WELL AS 
  4. All records where {second check}
Rather, it is saying :
Expand|Select|Wrap|Line Numbers
  1. Get me all records where {first check} AS WELL AS {second check}
Thus, records are only selected when both checks succeed.

You need to use the OR conjunction instead as has already been said by Jerry.

For more flexibility use the IN() function (as per Jared's post). Two checks is fine with OR but going beyond that is better with IN().
Aug 25 '10 #4
ck9663
2,878 Recognized Expert Specialist
I'll throw a wrench :)...

If you're using an OR in any of your condition, place the most probable TRUE condition first. If you're using an AND, place the most probable FALSE condition first.

This way, a complicated condition need not be test throughout. In OR, only one of the condition needs to be TRUE to make the entire condition as TRUE. In an AND, only one condition needs to be FALSE to make the entire condition as FALSE.

Although it's not always 100% that the server will parse the condition from left to write, it usually do.

Happy Coding!!!

~~ CK
Aug 25 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1862
by: Jim Moseby | last post by:
I stumbled across this while trying to update a table with a timestamp type column. At the time, I didn't know that the timstamp column would update itself when a row was changed. A kind gentleman in another group pointed that out to me. I added a column to a table and wanted to update the rows to populate the new column. When doing something like this I usually will create a temporary table and perform a dry run, just to make sure I am...
7
2401
by: andri.wardhana | last post by:
Hi Guys, I have a problem with my ASP file. since I'm all new in ASP, i found that the error statement generated by ASP is confusing. basically what I want to do in this script is ability to change password. Currently this script's running well in the PHP version ( I rewrote the entire PHP app to ASP app): 1. The form contains these fields : old password, new passwd, confirm new passwd. users have to input old passwd in order to change...
0
1855
by: leavandor | last post by:
I am trying to design a query that works with a relationship between a Table and a Query. I am comparing a value in the table with a computed value inside the query. The reason for this is that the Query calculates a field to become identical to the corresponding table field, for instance: Table 1 contains field "ID", which is WV008A00 Table 2 contains field "ID In", which is WV001000
1
5589
by: JM | last post by:
Hello, A very simple select query (no joins) to a linked ODBC SQL Server 2000 table produces incorrect results. The right number of rows seem to be returned, but some of the columns have incorrect values. I converted the query to a pass-through, and it worked as expected. Does anybody have an idea as to why this might happen? I'd rather leave the query as Jet, because it's supposed to be updateable. I'm converting an Access 2000...
6
27854
by: Roy Gourgi | last post by:
Hi, I am trying to add a row to my table but I get the error message "invalid column name SOBN and BN1" on this statement. Basically, I am trying to add the row into the same table that I am searching if it does not find SOBN = 5 and BN1 =3. What is the problem? Do I have to create a primary key? Is it possible to have more than 1 primary key (i.e. secondary ....... ). strCommand = "INSERT INTO tblSQL_2 (SOBN, BN1) SELECT SOBN , BN1...
1
1884
by: keliie | last post by:
I have a relatively simple (I assume) issue which I am at a complete loss to address. My issues is: I want to populate fields in my tables with summary data from the same table. Let me explain: tblItemDetails (contains data on food products purchased) Item_Description_ID (key, source link to tblMenuItemRecipe) Item_Unit_of_Measure Item_Location Item_Type Item_Category
2
5274
by: filmar | last post by:
I have two tables and need to recieve counts of each groups in columns. The 1st table is necessary to recieve exactly 4 rows even if there no one match condition id the 2nd table. It have to count if checked is equal to 1. CREATE TABLE . ( NOT NULL , ) ON GO CREATE TABLE . (
0
1129
by: whome | last post by:
Hello, in the query below, i'm trying to compare the first 3 characters of the symbol value ASymbol with first 3 characters of FinSymbol which are in the same table. You can have more than one FinSymbol in the table. is there a way to compare ASymbol to all FINSymbols? The query should only give results when ASymbol does not match any FINSymbols currently, this query is giving me results when ASymbol=XXX FinSymbol=YYY but my...
14
6669
by: Supermansteel | last post by:
My team at work uses Cognos to run multiple queries to pull in data. Then they take that data and import into Access and then usually run an Append Query to run a RND function to pull out a few samples for them to review the accounts. I was making a suggestion to my team that maybe if we only ran one Cognos query and pulled in all of the columns that everyone needs to pull samples for each of there tests that this would be better on the time...
2
2919
dlite922
by: dlite922 | last post by:
I have a permission table that gives a userID permission to a module and the any actions within that module. What I want to do is duplicate his permissions to another user. Permission table has: id (PK) userID (FK) module action
0
7987
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7899
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8392
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8397
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8050
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
5850
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3897
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2412
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1250
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.