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

UNION Query for Alternate Names

675 512MB
Assume 2 tables
tblP {Primary Table}
tblP.Key {AutoNumber and all that}
tblP.Name {Name of EE, Movie, Bird Species, or Whatever}

tblA {Alternate Table}
tblA.Key {AutoNumber and all that}
tblA.PtrToP {Link to tblP.Key so tblA can be joined, or displayed in form}
tblA.AltName {Alternate Name for EE, Movie, Bird Species, or Whatever}

Assume I am working with 2 tables with movie titles. Title for a movie might be "2 Days", or is it "Two Days" I want the query to find this, whether user types "2 Day" or "Two Day" So my primary table, tblP, has a row with key=7 and title = "2 Days" and tblA has a row with PtrToP=7 and AltName="Two Days"

My user enters "Two Days"

SELECT PtrToP FROM tblA WHERE (((AltName) Like "*Two Days*")) UNION SELECT tAAA.Key FROM tblP WHERE (((Name) Like "*Two Days*"))

This query gives me one row, with one field, and that field has the value 7. No problem.

Now I want to display all titles found. I somehow need to do another union, this time for the Movie Name, but will each half of the union have an inner join?

The best example I can come with is to go to "www.Netflix.com" and type "Rogue" into the search box. "Rogue" is an alternate title to a movie called "War", and their search finds both a movie called "Rogue" and a movie called "War" with an alternate title "Rogue". That is what I am trying to do!

OldBirdman
Dec 15 '07 #1
5 1823
FishVal
2,653 Expert 2GB
Hi, OldBirdman.

I think the current table structure is not suited well for it.
The following scheme will be more suitable.

tblIdentities
keyIdentityID Autonumber(Long), PK
lngPrimaryName Number(Long), FK(tblIdentityNames.keyIdentityNameID)

tblIdentityNames
keyIdentityNameID Autonumber(Long), PK
keyIdentityID Number(Long), FK(tblIdentities.keyIdentityID)
txtIdentityName Text

Regards,
Fish
Dec 15 '07 #2
OldBirdman
675 512MB
I knew that. As this program is for my personal use, managing a table with the name in it is easier, rather than a table of names. "Good" database design says you are correct.

It seemed so easy to get a list of keys and then query both tables. I was doing this for a learning experience as well as a solution. What started as a simple list to keep track of movies I have rented has become a fairly complex program.

Thank you again for your thoughts and ideas. As I do not know anybody who uses Access, this forum is my only place to exchange ideas.

OldBirdman
Dec 15 '07 #3
FishVal
2,653 Expert 2GB
Well.

Seems that you'll need to use your query returning keys to filter both tables (using INNER JOIN) and then union both datasets - the cost of tables' structure current design. ;)
I appreciate "good" database design because it makes things easier.

Regards,
Fish
Dec 15 '07 #4
OldBirdman
675 512MB
Thanks again for humoring me. Sometimes "Good" database design conflicts with simple table design. As there is only one user, me (at least for now, but I'm trying to get some local DVD Rental stores to put in a slightly different version as a kiosk for location. Instead of "Seen"/"Not Seen", it would return a classification or location, ie Drama, Comedy, . . .)

I'll probably move all titles to their own table, but I may play awhile longer to see if I can get it to work this way, as a learning exercise.

OldBirdman
Dec 15 '07 #5
OldBirdman
675 512MB
After 2 months of meditation and cogitation (and some rumination), I have decided that this question belongs in an AddressBook environment. I have begun rewriting my address book, and I certainly do not want UNION queries.

See also "SQL INNER JOIN with another SELECT Query" also posted to this forum.

When I first wrote my Address Book program, everyone had 1 phone, 1 address, and 1 spouse.

I now look at my primary table (tAAA) and note that every field can have multiple entries, therefore these are related tables, with fields pointing to the Key field in tAAA.

Name = "Foreign Auto Repair" or "Dave"
Address = "123 Main, Miami, FL" or "c/o FedEx, 876 Central, Miami, FL"
Phone = Cell: ; Land: ; VoiceMail: ;
etc

Has anyone designed a system such that the primary/central/main table has only 1 field, the KEY field? That seems to be where I am headed, but I never heard of such a thing.

Please point me in the direction of discussions, white papers, blogs, etc. on this concept.

OldBirdman
Feb 24 '08 #6

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

Similar topics

0
by: Paradigm | last post by:
I am trying to make a union query to join 4 tables. I have reduced the tables to just 5 fields and made sure that the field types and names are the same. I keep getting an error message ODBC call...
10
by: jqq | last post by:
SQL2K on W2Kserver I need some help revamping a rather complicated query. I've given the table and existing query information below. (FYI, changing the database structure is right out.) The...
3
by: Dalan | last post by:
From reading Access 97 help text, it seems that to do what I need to do will require a Union Query. As this would be my first, I think I might require a little guidance. I have two tables with...
4
by: shaun palmer | last post by:
when or Where do you use a union query ? how can I wright sql, tblPopulation,* tblcustomer,* one to one with all the appropriate attributes(field). Your help would be greatly...
2
by: Lyn | last post by:
Hi, How do you bind the output columns from a UNION query when the fields from the two tables have different names? Consider this query (WHERE clauses omitted)... SELECT SurnameBirth,...
3
by: mikes | last post by:
I have 2 separate queries, which effectively are the same except they draw data from separate tables. Both tables are (design-wise) identical, only the data is different. for each query, there are...
7
by: jjmontreal | last post by:
Help, Short story is I have 2 tables. 1 for the Companies and 1 for the Employees. These are used in a Main form where the user enters the Company info with a sub form for the employees info. (1 to...
5
zachster17
by: zachster17 | last post by:
Hi everyone, First of all, sorry for the massive amount of SQL I am about to type. I have a database that has a "lives" table of insured employees and then another table (that links to the lives...
3
by: jim | last post by:
Does anyone know why the query below would return numbers? I'm attempting to produce a report that shows in *one* column the names that appear in multiple columns in a single table. Table Name:...
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...
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
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...
1
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
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.