473,438 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,438 software developers and data experts.

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

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

where tbl.gallery='Abstract' and tbl.gallery='Abstract 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 1473
Jerry Winston
145 Expert 100+
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 Expert 2GB
alternatively,
Expand|Select|Wrap|Line Numbers
  1. tbl.gallery in ('Abstract','Abstract art','Modern art')
Jared
Aug 25 '10 #3
NeoPa
32,556 Expert Mod 16PB
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 Expert 2GB
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
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...
7
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...
0
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...
1
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...
6
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...
1
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: ...
2
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...
0
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...
14
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...
2
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
1
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...
0
agi2029
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.