473,386 Members | 1,867 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,386 software developers and data experts.

Find records that comply with either or criteria

I am trying to get of our the database of our finance system all records where the the first field is the same and that either comply with condition a or condition b.

Example:

[HTML]
/<font face='Courier'
>field 1 field 2 field 3 field 4<
>179000 990001 0 100.00<
>179500 100001 TAB123 123.00<
>180000 100002 TAB250 250.00<
>180000 990002 0 1000.00<
/font>
[/HTML]
The conditions for the query are:
condition a: where field 3 LIKE 'TAB%'
condition b: where field 2 LIKE '99%'

The result I wish to see is:

[HTML]
/<font face='Courier'
>field 1 field 2 field 3 field 4<
>180000 100002 TAB250 250.00<
>180000 990002 0 1000.00<
/font>
[/HTML]

because field 1 is the same for both records and either condition a or condition b are met. The first and second records disqualify, because there is no second record with an equal value in field 1 and that matches the other condition.

I would be very obliged if someone could help me with the issue. I think I spent to much time thinking around it!

Many Txs
Wolfgang
Nov 29 '06 #1
1 3309
iburyak
1,017 Expert 512MB
1.

select * from table_name a
where ([field 3] like 'TAB%' and exists (select * from table_name where [field 1] = a.[field 1] and [field 2] like '99%'))
or ([field 2] like '99%' and exists (select * from table_name where [field 1] = a.[field 1] and [field 3] like 'TAB%'))


2.
select * from table_name a
where [field 1] in (select [field 1]
from table_name
where [field 3] like 'TAB%' or [field 2] like '99%'
group by [field 1]
having count(*) = 2)
Nov 29 '06 #2

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

Similar topics

3
by: Jonathan | last post by:
Hi all! For a match schedule I would like to find all possible combinations of teams playing home and away (without teams playing to themselves of course). I now the simple version works...
1
by: KLAU | last post by:
I have a field that retrieves information from an expression in a query. I have used a DLookup function to get the calculated field from the query. However, the relationship is 1-to-many so one...
3
by: Tom Mitchell | last post by:
All: I'm stumped on a query. How do I find duplicates in a table where one of the duplicates has values is a certain field and the other doesn't. For example, I have the following table: ...
3
by: Bob C. | last post by:
When I migrated my tables to SQL Server I needed a way to overcome the slow performance of the Find method on my recordsets. Although this can be done by accessing the table directly using dao and...
13
by: Sue | last post by:
I'm working on a database that keeps track of employees hired by a general contractor on a project by project basis. These employees are hired to work on a project and are then laid off either at...
1
by: Rinee | last post by:
Hi, I have a database of a bunch of contractors who have signed a safety agreement with us, their contact info, their insurance info, etc. Each was assigned an ID number as the main key. Each...
5
by: Col | last post by:
I have a query with criteria that comes from a combo box on a form. I'd like to set the query up so the user can either limit the criteria to the selection in the combo box or the user can pull all...
1
by: Bhujanga | last post by:
I have some reports whose purpose is to show whether any records currently meet certain criteria, so of course the report is based on a query where that criteria is defined. If there don't happen to...
2
by: Clinton M James | last post by:
Hi All, I have set up an access database that I communicate with through Excel and VBA. The purpose is to do auditing of staff. Because there are several audits, each audi has differing...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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
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...

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.