473,378 Members | 1,512 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.

Using definitions table for lookup in records

Hi all,

Am struggling here with how to use records in one table to lookup matches in another table records.

Table1 contains the lookup terms and is called 'defTable' which has a Field 'Name' and records:

Cat
Dog
Fish
Pony

Table2 is called 'custTable' which has a Field 'Details' and records:

MrsSmithhasaCatwhosenameistabby
johnthoughhisFishwassick
JasonsDoghasbeenshedingthisweek

I want to search all the records in defTable for a match in each record of custTable and return the match text

i.e.

MrsSmithhasacatwhosenameistabby returns Cat
johnthoughhisFishwassick returns Fish
JasonsDoghasbeensheedingthisweek returns Dog

Thanks for your time

Mark.
Aug 8 '10 #1
14 1378
Jerry Maiapu
259 100+
Mark,
You problem should be take care of if you know more about table relationships.
Relate the tables. (1:many)..

(defTable:custTable)
Aug 8 '10 #2
Hey there,

Not sure I understand? I related the tables 1:many and tried entering a query with criteria instr(1,Name,Details) but Details is type memo so the join fails...

Thanks,

Mark
Aug 9 '10 #3
Jerry Maiapu
259 100+
Why not create num field in custTable and join with Auto number field in defTable.
That'll do. You cannot create relationships using memo type fields
Aug 9 '10 #4
Delerna
1,134 Expert 1GB
If I am understanding you correctly

The key point here is
Am struggling here with how to use records in one table to lookup MATCHES in another table records.
I think you need to join the two tables to achieve your goal
and the only way you could join two tables
on a field with the value Cat in one
and MrsSmithhasaCatwhosenameistabby in the other joining fields would be through the keyword like

Expand|Select|Wrap|Line Numbers
  1. SELECT field list
  2. FROM table1
  3. JOIN table2 on table1.f like '%' + table2f + '%'
  4.  
There are 2 problems here
1) That is not legal syntax, you can't use like in a join expression
2) Even if it was legal syntax it could produce very slow queries.


I think you might need to rethink what you are trying to do.....there is always more than one way to skin a cat

Try using recordsets in vba
Aug 9 '10 #5
Hi all,

So I did figure out how to solve this problem:

Expand|Select|Wrap|Line Numbers
  1. SELECT defTable.Name
  2. FROM defTable, Cust
  3. WHERE (((Cust.Details) Like "*" & [defTable].[Name] & "*"))
  4. ORDER BY Cust.ID;
Thanks for the hints. I got there.

Mark.
Aug 9 '10 #6
NeoPa
32,556 Expert Mod 16PB
This is a solution Mark, but is somewhat jumbled in its makeup (although should produce the results you require). Try this :
Expand|Select|Wrap|Line Numbers
  1. SELECT   tDT.Name
  2. FROM     Cust AS tC INNER JOIN
  3.          defTable AS tDT
  4.   ON     tC.Details Like '*' & tDT.Name & '*'
  5. ORDER BY tC.ID
As a general rule it is worth avoiding any processing based on cartesian products (See SQL JOINs).
Aug 9 '10 #7
NeoPa
32,556 Expert Mod 16PB
Delerna: There are 2 problems here
1) That is not legal syntax, you can't use like in a join expression
2) Even if it was legal syntax it could produce very slow queries.

<snip>
Try using recordsets in vba
I don't mean to contradict, but Like is usable in a JOIN expression. Certainly within Jet-SQL.

I agree that anything along these lines would be fundamentally slow, however :
  1. Anything based on a cartesian product with a WHERE clause could only be slower still. It may manage to keep up due to optimisations, but logically it can never be faster.
  2. Recordsets are themselves built on SQL of some form. I can't conceive of a scenario where something could perform quicker at the client end (with recordset processing) than could be possible at the server end (SQL).
I can't claim to have done thorough time trials on any of this, but the SQL I posted did work for me in a very similar environment.
Aug 9 '10 #8
Delerna
1,134 Expert 1GB
I don't mean to contradict, but Like is usable in a JOIN expression.
...
...
I can't claim to have done thorough time trials on any of this, but the SQL I posted did work for me in a very similar environment.
hmmmmm
contradict me if I am wrong by all means but when I tried it, and I haven't done extensive testing either as I just threw something together to try out the theory for this question, I got an error message along the lines that like could not be used in that context and concluded that it is not legal syntax.

Based on your experience I'll try again and see what the error I got really meant.

By the way, apologies for the %, I develop using microsoft SQL server and that is the sytax for it.
Aug 9 '10 #9
Delerna
1,134 Expert 1GB
Neopa, You are correct. I had accidentally selected Memo for the field types and the error was actually fields of type Memo cannot be used in joins. When I saw the error I made an assumption and we all know what happens when we assume
Aug 9 '10 #10
NeoPa
32,556 Expert Mod 16PB
Really no need to apologise Delerna. I make mistakes regularly. You've more than earned the right to one or two.

As for the % syntax, although SQL Server does indeed use this as standard, this is not a package relateive thing as much as a standards one. Access, from 2003 onwards, has had an option to be ANSI-92 compliant, rather than the ANSI-89 as supported by previous versions. Thus it is not correct to say Access doesn't use the % syntax. It merely isn't used often. Most Access dbs out there seem to use the ANSI-89 (*) syntax still. The rest of the world will catch up with you some day soon I expect ;)
Aug 9 '10 #11
Delerna
1,134 Expert 1GB
Yea, especially as I get older mistakes come easier.


Incidentally, my comment on producing slow queries was just a gut feeling I had when thinking about a text like this.

Dogbreath's nicname is eponymous to a dogs breath and his concatenation techniques are fishy to say the least

and the matches a query using like in a join
(if you could and as it turns out you can)
might return.

This record alone would return 4 matching records for the bolded parts and I feel that none of them were actually meant to be matches. Using like in a where condition here would only return the record once although still accidentally.
There would of couse be ways around this, by putting a leading and trailing space on the words in the defTable for example
Aug 10 '10 #12
Delerna
1,134 Expert 1GB
Ps
That said, I do agree with the counter points Neopa raised
Aug 10 '10 #13
NeoPa
32,556 Expert Mod 16PB
Delerna: Dogbreath's nicname is eponymous to a dogs breath and his concatenation techniques are fishy to say the least
It's a valid point, but I would guess from the OP's first post that they're more interested in seeing all the flag words than finding each record as such. Their question only mentions displaying the flag word, yet one must suppose that was to keep it short and to the point. I expect other fields are displayed also, that they need no help with.

Bear in mind also, the data seems to be all of a type - Comments related to animals managed at some form of menagerie. A couple of false positives probably wouldn't be the end of the world.

Other techniques can be used of course, to give similar and even different results, should that be required.

Lastly, nice example sentence :) Quite innovative.
Aug 10 '10 #14
Delerna
1,134 Expert 1GB
Yes, I had a chuckle over that sentence too
Aug 10 '10 #15

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

Similar topics

4
by: webhigh | last post by:
Iım not sure if this a PHP question or an MySQL question but here it goes. I have a repeat region of a table called userid What Iım trying to accomplish is being able to edit the record and...
1
by: Eranut | last post by:
Hi, I am trying to understand if there is a way to send a table of records (table of structs) from pro C to Oracle pl/sql stored procedure. Since Oracle is demanding definition of the *sent*...
2
by: ImraneA | last post by:
Hi there Application : Access v2K/SQL 2K Jest : Using sproc to append records into SQL table Jest sproc : 1.Can have more than 1 record - so using ';' to separate each line from each other.
4
by: Larry Rekow | last post by:
In Access I have a macro that, each night, takes a table with a primary key defined in it, and deletes all the rows. Then it imports/appends records from a fixed width text file. In this way,...
0
by: Pallav | last post by:
please disregard my earlier post on sine table lookup. i've located the problem. seems to be due to errors compounding in fixed-point multiply which cause wrong table lookup. thanks pallav
1
by: Mike | last post by:
In C, we can typedef pointer to functions, and therefore use function tables. But what's the advantage of using function table? Thanks, Mike
5
by: Przemek Wrzesinski | last post by:
Hi, I'm trying to add additional column using 'alter table' command via OleDB to Excel workbook (one sheet called queExportBOND): Dim strConn As String strConn =...
4
by: Michael R | last post by:
Hi. I'm currently dealing with the following: I need a drop box that will have in it a certain range of accending consuquential numbers for ex: 1, 2, 3, 4, 5, 6, 7. The min and the max number...
2
by: cj | last post by:
We have a legacy accounting system (not developed in house) here that happens to be written in Visual FoxPro. One of the tables has an index that is actually a coded function COMPANY1 ...
0
debasisdas
by: debasisdas | last post by:
This thread contains some useful tips for using External tables. USING EXTERNAL TABLE ======================= 1.THE TABLE POINTS TO EXTERNAL FILE. IF DATA IS ALTERED IN THE EXTERNAL FILE,DATA...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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:
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: 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?
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...

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.