473,714 Members | 2,402 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
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
Aug 17 '10 #1
4 1504
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
3,406 Recognized Expert Specialist
Expand|Select|Wrap|Line Numbers
  1. tbl.gallery in ('Abstract','Abstract art','Modern art')
Aug 25 '10 #3
32,569 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
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

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...
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...
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
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...
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...
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
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 . (
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...
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...
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
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...
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,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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

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.