473,657 Members | 2,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find records that comply with either or criteria

1 New Member
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 3322
iburyak
1,017 Recognized Expert Top Contributor
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
7872
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 something like this: For a (very) simple table containing three rows like this: row 1: A
1
20776
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 site could have many units. How do I have the DLookUp field value change to a newly calcuated field when I navigate through the units? please see example below: On the Form: A site can have many units.
3
4600
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: tblItems ItemID ItemLabel
3
1897
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 odbc, or by using a parameter query that's customized in code for each search, I was able to find a simple and fast solution based on the same native Access SELECT query I used previously with native Access tables. In my example I open an...
13
5833
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 the end of the work they were hired to do or at the end of the project. Any employee may be hired, laid off and rehired several times during the course of time. The tables I have and the critical fields to my question are: TblEmployee EmployeeID...
1
2260
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 contractor agreement has an expiry date. I have a report that lists the contractors and a couple other relevant fields for reference for our company employees. But I don't want a contractor to appear on this report (which looks like a list of...
5
1821
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 records. Can't figure out a way for the query to pull all records. Currently uses the criteria !!. I've tried a couple of things to allow for the option of all records, but without any luck. Any suggestions?
1
1887
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 be any records that satisfy the criteria at a particular time then the report produces with one line in the detail section that says "#Error". This confuses the users becuase they think there is something wrong with the report. Is there a way to...
2
1160
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 criteria to mark on, therefore the vba program I have made is dynamic in that the user can construct as many marking criteria as needed.
0
8310
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
8826
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
8605
tracyyun
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...
0
7330
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, 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...
1
6166
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
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
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.