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

Query to include all records from one table, even if they dont match criteria

I have an input table that I want to query against another table.

Column 1 of input table is an ID that matches with a column in the 2nd table. Column 2 is a number that should fall between two numbers (columns 2 and 3) in the 2nd table to further select a specific row in the 2nd table.

It works great if the number in column 2 of the input table falls within a set of the two numbers. If it doesn't, that ID does not show up in the query. I have tried the outer join to have all records of table 1 show up but since I am using the criteria,

"Between [tbl2]![col2] and [tbl2]![col3]"

it doesn't show anything if the input data is not between those two numbers.

Here's an example. Since 11 is outside the ranges for D in table 2, nothing shows up in the query results.

Table1
Col1 Col2
D . . . .11

Table2
Col1. . Col2 . .Col3
D. . . .1 . . . 6
D. . . .7 . . . 10
K . . . 737 . . 272
...

I somehow need to query table2 to find the minimum of column2 and maximum of column3 and then if table1 column2 is Not Between that range to show that there was no match. I am not sure how to do that so any help would be appreciated.
Jun 5 '15 #1
5 4761
Seth Schrock
2,965 Expert 2GB
In the query design view, double click on the line that joins the two tables. Select the option that shows all the data from the table that you are wanting and only the data where the second table matches. I think that this will do what you are looking for.
Jun 5 '15 #2
Seth,

I have tried that but it still will not show a Row for a particular ID in table 1 if the criteria "between" is not met.
Jun 8 '15 #3
Seth Schrock
2,965 Expert 2GB
Then you may have to do it as a subquery. Create a query on tbl2 that has your WHERE clause and then create a second query that combines the previous query with the other table.
Jun 8 '15 #4
Rabbit
12,516 Expert Mod 8TB
For the outer join to work, you need to put that criteria in the join condition and not as a filter condition. You will have to do that through the SQL view because it is a complex join that is not supported by the GUI.
Jun 8 '15 #5
NeoPa
32,556 Expert Mod 16PB
An alternative approach is to ensure that the criteria is such that what you want to show will never fail. When the record from the right side of a LEFT JOIN is absent then all of its fields will be Null.

IE.
Expand|Select|Wrap|Line Numbers
  1. ([L].[X] Between [R].[Col1] And [R].[Col2]) OR ([L].[X] Is Null)
or alternatively :
Expand|Select|Wrap|Line Numbers
  1. (Nz([L].[X],[R].[Col1]) Between [R].[Col1] And [R].[Col2])
The latter being less wordy but also less efficient if that matters ;-)

NB.
In this example [L] -> Left table & [R] -> Right table.
Jun 9 '15 #6

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

Similar topics

0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
1
by: Rhanda Zak | last post by:
Hi all, my question is maybe so trivial, that I even could not find it in Google's NG seach, so I annoy you now: I simply want to copy the result of a SELECT query to another table which has...
1
by: grime | last post by:
Thanks in advance for the help... should be an easy one for you all. I have a access table where I have the following fields: Product Sales I want to add a 3rd column (AdjustedSales) where if...
2
by: NowItsWhatever | last post by:
In query DESIGN view, how do I automatically "fit" the columns in the table/field grid to the lengths of the table and field names (including any functions applied to the fields). I am not talking...
5
by: binky | last post by:
Question for all you SQL gurus out there. I have a (seemingly) complex query to write, and since I'm just learning SQL server, am not sure how to go about it. Tables: t_trans t_account All...
4
by: Sharkiness | last post by:
Hi, I'm new to using queries in Access and am stuck on trying to run a query from a table. I have thousands of records with fields such as customer name, Company Name, Company Country and...
4
by: fran7 | last post by:
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...
5
by: slenish | last post by:
Hello all, I am wondering if its possible to do a Union All Query for 1 table instead of mulitiple tables. I have 7 columns that im trying to Union. I have it working to an extent right now...
3
by: Ann VK | last post by:
I have a table with records like: ID End Price A 20060625 5.70250000000000000000 A 20060725 5.76500000000000000000 A 20060825 5.70438000000000000000 A 20060925 5.71000000000000000000...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
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
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...
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,...

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.