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

Joining fields in queries using partial values

Question about joins in queries. I have 2 tables with a field called
"ID".

Table 1
Rec1 = Jan12FredFlintstone
Rec2 = Feb01WilmaRubble

Table 2
Rec1 = Jan12BarneyRubble
Rec2 = Mar03SamSlate

I'm trying to write a query that says show me all values where
Left([table 1].[id],5) = Left([table2].[id],5). I don't know how to
enter this into a query window. Do I need to join the tables somehow?
I tried just adding both tables without joining and entering the
parameters like I have above, but system froze. I have 30,000 records
in each table if that matters.

I don't want to create a new field that just has the left 5 of the ID
field if it's not needed.

Thanks,
D

Sep 6 '06 #1
12 5525
This design is serious bad news. You can't create joins on partial
matches. You either have a match or you don't. Split the values in a
query, then try joining the resulting queries.

Sep 6 '06 #2
On 6 Sep 2006 12:24:49 -0700, "ve***@aol.com" <ve***@aol.comwrote:

Sure that works. Here is an example using the Northwind sample
database:
SELECT Customers.CustomerID, Employees.EmployeeID,
Customers.ContactName, Employees.FirstName, Employees.LastName
FROM Customers, Employees
WHERE ((Left$([ContactName],5)=Left$([FirstName],5)));

I agree with PietLinden: you have a seriously problematic db design,
and you will have more problems down the road if you don't redesign.

-Tom.

>Question about joins in queries. I have 2 tables with a field called
"ID".

Table 1
Rec1 = Jan12FredFlintstone
Rec2 = Feb01WilmaRubble

Table 2
Rec1 = Jan12BarneyRubble
Rec2 = Mar03SamSlate

I'm trying to write a query that says show me all values where
Left([table 1].[id],5) = Left([table2].[id],5). I don't know how to
enter this into a query window. Do I need to join the tables somehow?
I tried just adding both tables without joining and entering the
parameters like I have above, but system froze. I have 30,000 records
in each table if that matters.

I don't want to create a new field that just has the left 5 of the ID
field if it's not needed.

Thanks,
D
Sep 6 '06 #3
Great, looks like that worked. Thanks Tom! Guess I wrote it
incorrectly. Thanks for mention on DB design. They actually are split
out and a combo of 4 fields. I won't bore anyone with why they are
combined here but this should solve my current issue nonetheless!

Tom van Stiphout wrote:
On 6 Sep 2006 12:24:49 -0700, "ve***@aol.com" <ve***@aol.comwrote:

Sure that works. Here is an example using the Northwind sample
database:
SELECT Customers.CustomerID, Employees.EmployeeID,
Customers.ContactName, Employees.FirstName, Employees.LastName
FROM Customers, Employees
WHERE ((Left$([ContactName],5)=Left$([FirstName],5)));

I agree with PietLinden: you have a seriously problematic db design,
and you will have more problems down the road if you don't redesign.

-Tom.

Question about joins in queries. I have 2 tables with a field called
"ID".

Table 1
Rec1 = Jan12FredFlintstone
Rec2 = Feb01WilmaRubble

Table 2
Rec1 = Jan12BarneyRubble
Rec2 = Mar03SamSlate

I'm trying to write a query that says show me all values where
Left([table 1].[id],5) = Left([table2].[id],5). I don't know how to
enter this into a query window. Do I need to join the tables somehow?
I tried just adding both tables without joining and entering the
parameters like I have above, but system froze. I have 30,000 records
in each table if that matters.

I don't want to create a new field that just has the left 5 of the ID
field if it's not needed.

Thanks,
D
Sep 6 '06 #4
Spoke too soon. I wrote my question wrong I think. I'm trying to show
all the values that are in one table but NOT in the other.

So the Left(table1) = Left(table2) does work if I was trying to show
the equal values but if I substitute <for = that doesn't work. So in
my original example, from Table 1 I'd expect to only see Rec2 because
the left 5 of that record is not in Table 2.

ve***@aol.com wrote:
Great, looks like that worked. Thanks Tom! Guess I wrote it
incorrectly. Thanks for mention on DB design. They actually are split
out and a combo of 4 fields. I won't bore anyone with why they are
combined here but this should solve my current issue nonetheless!

Tom van Stiphout wrote:
On 6 Sep 2006 12:24:49 -0700, "ve***@aol.com" <ve***@aol.comwrote:

Sure that works. Here is an example using the Northwind sample
database:
SELECT Customers.CustomerID, Employees.EmployeeID,
Customers.ContactName, Employees.FirstName, Employees.LastName
FROM Customers, Employees
WHERE ((Left$([ContactName],5)=Left$([FirstName],5)));

I agree with PietLinden: you have a seriously problematic db design,
and you will have more problems down the road if you don't redesign.

-Tom.

>Question about joins in queries. I have 2 tables with a field called
>"ID".
>
>Table 1
>Rec1 = Jan12FredFlintstone
>Rec2 = Feb01WilmaRubble
>
>Table 2
>Rec1 = Jan12BarneyRubble
>Rec2 = Mar03SamSlate
>
>I'm trying to write a query that says show me all values where
>Left([table 1].[id],5) = Left([table2].[id],5). I don't know how to
>enter this into a query window. Do I need to join the tables somehow?
>I tried just adding both tables without joining and entering the
>parameters like I have above, but system froze. I have 30,000 records
>in each table if that matters.
>
>I don't want to create a new field that just has the left 5 of the ID
>field if it's not needed.
>
>Thanks,
>D
Sep 6 '06 #5

ve***@aol.com wrote:
Spoke too soon. I wrote my question wrong I think. I'm trying to show
all the values that are in one table but NOT in the other.
create an outer join - use the Find Unmatched query wizard.

Sep 6 '06 #6
Hate to be a nuisance but I do have an idea how to do the unmatched,
but not with a partial field. Can't use "Is Null" because I only want
to match partial.
pietlin...@hotmail.com wrote:
ve***@aol.com wrote:
Spoke too soon. I wrote my question wrong I think. I'm trying to show
all the values that are in one table but NOT in the other.

create an outer join - use the Find Unmatched query wizard.
Sep 6 '06 #7
You would have to base in on the query Tom gave you, or something like
it. (I bet normalization is sounding pretty good right about now...)

SELECT Customers.CustomerID, Employees.EmployeeID,
Customers.ContactName, Employees.FirstName, Employees.LastName
FROM Customers, Employees
WHERE ((Left$([ContactName],5)=Left$([FirstName],5)));
Then you'd base your Find Unmatched query on a query like the above

Sep 6 '06 #8
You would have to base in on the query Tom gave you, or something like
it. (I bet normalization is sounding pretty good right about now...)

SELECT Customers.CustomerID, Employees.EmployeeID,
Customers.ContactName, Employees.FirstName, Employees.LastName
FROM Customers, Employees
WHERE ((Left$([ContactName],5)=Left$([FirstName],5)));
Then you'd base your Find Unmatched query on a query like the above

Sep 6 '06 #9
pi********@hotmail.com wrote in
news:11**********************@i3g2000cwc.googlegro ups.com:
This design is serious bad news. You can't create joins on
partial matches. You either have a match or you don't. Split the
values in a query, then try joining the resulting queries.
Of course you can do non-equi joins. You just can't do them in the
QBE.

But it's non-optimal, as the join can't use indexes. The examples
are clearly cases where the parts of the single value should be
stored in multiple fields.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Sep 6 '06 #10
Of course you can do non-equi joins. You just can't do them in the
QBE.

But it's non-optimal, as the join can't use indexes. The examples
are clearly cases where the parts of the single value should be
stored in multiple fields.
David,
could you post an example? Joining on something like
INNER JOIN ON LEFT(tableA.MyField,4) = LEFT(tableB.OtherField,4) ?

Sep 7 '06 #11
pi********@hotmail.com wrote:
Of course you can do non-equi joins. You just can't do them in the
QBE.

But it's non-optimal, as the join can't use indexes. The examples
are clearly cases where the parts of the single value should be
stored in multiple fields.

David,
could you post an example? Joining on something like
INNER JOIN ON LEFT(tableA.MyField,4) = LEFT(tableB.OtherField,4) ?
SELECT tableA.MyField, B.OtherField
FROM tableA INNER JOIN tableB
ON LEFT(tableA.MyField,4) = LEFT(tableB.OtherField,4)

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Sep 7 '06 #12
pi********@hotmail.com wrote in
news:11**********************@i42g2000cwa.googlegr oups.com:
>Of course you can do non-equi joins. You just can't do them in
the QBE.

But it's non-optimal, as the join can't use indexes. The examples
are clearly cases where the parts of the single value should be
stored in multiple fields.

could you post an example? Joining on something like
INNER JOIN ON LEFT(tableA.MyField,4) = LEFT(tableB.OtherField,4) ?
Post an example of what? The SQL for this was posted in other
replies, to which *you* replied.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Sep 7 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gianfranco | last post by:
Hi I got a problem with 2 tables. I have a table, say A, with x records, coming from a make table query and a table, say B, with y records, coming from another make table query. I need to join...
6
by: AAVF | last post by:
Hi We have a problem with a query. An Access database links via ODBC to a UNIX server. To speed things, we use the ODBC to load the relevant tables to the local PC that runs Access so that...
5
by: Megan | last post by:
Hi everybody- I'm helping a friend with a music database. She has an old one and is creating a new one. She wants to compare records and fields in the old database with records and fields in the...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
2
by: Dan Cook | last post by:
Ok... here's the scoop... I've got an unbound form with Serial Number, Building, and Room... all this is in tableA... Now I've got the form setup with building, room and serial number as combo...
3
by: VMI | last post by:
I'm currently using the dataAdapter.Fill method to fill my dataset with data from an Access DB. My dataset will contain a table with three fields from Access. In my datagrid (for user...
7
by: Dan | last post by:
(Using Classic ASP & MS Access) I have a page that has 120 fields on it (mostly checkboxes). I cannot split this into smaller pages. So what i want to do is write a class that handles this. in...
5
by: mike | last post by:
Question. I have a new table that I am adding to a script that I wrote. This table has 3 fields, the first 2 fields are used in the on statement as being = other fields in the script. The...
9
by: markla | last post by:
Hi, I have an EDM model, which I'm rendering using DynamicData pages. I need to add a derived/calculated field. For example, in a "Person" entity, I have LastName and FirstName. I need to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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:
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...

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.