473,406 Members | 2,345 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,406 software developers and data experts.

Tough SQL objective - pulling data from 4 different tables

MLH
I have tblVehicles, tblOwners, tblProxies, tblLienholders.
In the vehicles table are [OwnerID] and [ProxyID] identifying
owner and proxy (generally an attorney). Vehicles table is
child table to tblOwners and tblProxies. tblLienholders has
[VehicleJobID] and is a child table to vehicles table.

As you can imagine, owners, proxies and lienholders houses
names & addresses of persons/companies. At some point, I need
to extract a dynaset of vehicles and these other entities -
each in a record by itself. For instance, for a given vehicle -
say their were 2 lienholders, an owner and an attorney proxy.
I would like to produce a 4-record dynaset as follows:

'79 VW John Q Owner 109 Lazy Lane Raleigh NC 27615
'79 VW Alfred Attorney 22 Main St Cary NC 27511
'79 VW ABC Loans 19 Castle Ave New York NY 00211
'79 VW Car Quest 5491 Minnesota Anchorage AK 99518

Is that even remotely possible? Here are table structures...

tblVehicles tblOwners tblProxies tblLienholders
[VehicleJobID] [OwnerID] [ProxyID] [LienHolderID]
[OwnerID] [OwnAddr] [ProxAddr] [VehicleJobID]
[ProxyID] blah... blah... [LHaddr]
[VIN] blah... blah... blah...
[MakeModel] blah... blah... blah...
blah...
blah...
blah...
Nov 13 '05 #1
13 2374
>I have tblVehicles, tblOwners, tblProxies, tblLienholders.
In the vehicles table are [OwnerID] and [ProxyID] identifying
owner and proxy (generally an attorney). Vehicles table is
child table to tblOwners and tblProxies. tblLienholders has
[VehicleJobID] and is a child table to vehicles table.

As you can imagine, owners, proxies and lienholders houses
names & addresses of persons/companies. At some point, I need
to extract a dynaset of vehicles and these other entities -
each in a record by itself. For instance, for a given vehicle -
say their were 2 lienholders, an owner and an attorney proxy.
I would like to produce a 4-record dynaset as follows:

'79 VW John Q Owner 109 Lazy Lane Raleigh NC 27615
'79 VW Alfred Attorney 22 Main St Cary NC 27511
'79 VW ABC Loans 19 Castle Ave New York NY 00211
'79 VW Car Quest 5491 Minnesota Anchorage AK 99518

Is that even remotely possible? Here are table structures...

tblVehicles tblOwners tblProxies tblLienholders
[VehicleJobID] [OwnerID] [ProxyID] [LienHolderID]
[OwnerID] [OwnAddr] [ProxAddr] [VehicleJobID]
[ProxyID] blah... blah... [LHaddr]
[VIN] blah... blah... blah...
[MakeModel] blah... blah... blah...
blah...
blah...
blah...


What I would do is start with 2 or 3 queries and select the results you need
from those queries. Consolidate as you can. Use the query designer for
help with the joins if you need to.
Nov 13 '05 #2
MLH
If it cannot be done with one query, I'll have to do it using DAO -
walking the records manually. Won't be as elegant. Would much
rather do it from SQL.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

What I would do is start with 2 or 3 queries and select the results you need
from those queries. Consolidate as you can. Use the query designer for
help with the joins if you need to.


Nov 13 '05 #3
On Mon, 26 Sep 2005 22:49:56 -0400, MLH <CR**@NorthState.net> wrote:

Sounds possible, most likely using a 4-part union query. Each part
goes after one type of entity. I would recommend adding a column just
to identify the entitytype.

-Tom.

I have tblVehicles, tblOwners, tblProxies, tblLienholders.
In the vehicles table are [OwnerID] and [ProxyID] identifying
owner and proxy (generally an attorney). Vehicles table is
child table to tblOwners and tblProxies. tblLienholders has
[VehicleJobID] and is a child table to vehicles table.

As you can imagine, owners, proxies and lienholders houses
names & addresses of persons/companies. At some point, I need
to extract a dynaset of vehicles and these other entities -
each in a record by itself. For instance, for a given vehicle -
say their were 2 lienholders, an owner and an attorney proxy.
I would like to produce a 4-record dynaset as follows:

'79 VW John Q Owner 109 Lazy Lane Raleigh NC 27615
'79 VW Alfred Attorney 22 Main St Cary NC 27511
'79 VW ABC Loans 19 Castle Ave New York NY 00211
'79 VW Car Quest 5491 Minnesota Anchorage AK 99518

Is that even remotely possible? Here are table structures...

tblVehicles tblOwners tblProxies tblLienholders
[VehicleJobID] [OwnerID] [ProxyID] [LienHolderID]
[OwnerID] [OwnAddr] [ProxAddr] [VehicleJobID]
[ProxyID] blah... blah... [LHaddr]
[VIN] blah... blah... blah...
[MakeModel] blah... blah... blah...
blah...
blah...
blah...


Nov 13 '05 #4
There's nothing wrong with having multiple queries.

For instance, you can join two of the tables the way you need to and save
that as, say, Query1. You then join Query1 to another of the tables and save
that as Query2. Finally, you join Query2 to the 4th table and save that as
Query3. You then use Query3 everywhere you need the data.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"MLH" <CR**@NorthState.net> wrote in message
news:a4********************************@4ax.com...
If it cannot be done with one query, I'll have to do it using DAO -
walking the records manually. Won't be as elegant. Would much
rather do it from SQL.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

What I would do is start with 2 or 3 queries and select the results you
need
from those queries. Consolidate as you can. Use the query designer for
help with the joins if you need to.

Nov 13 '05 #5
MLH
Sounds like a plan. I'll have to read up a bin on union queries
a bit before starting. I'm not familiar with them.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Sounds possible, most likely using a 4-part union query. Each part
goes after one type of entity. I would recommend adding a column just
to identify the entitytype.

-Tom.

I have tblVehicles, tblOwners, tblProxies, tblLienholders.
In the vehicles table are [OwnerID] and [ProxyID] identifying
owner and proxy (generally an attorney). Vehicles table is
child table to tblOwners and tblProxies. tblLienholders has
[VehicleJobID] and is a child table to vehicles table.

As you can imagine, owners, proxies and lienholders houses
names & addresses of persons/companies. At some point, I need
to extract a dynaset of vehicles and these other entities -
each in a record by itself. For instance, for a given vehicle -
say their were 2 lienholders, an owner and an attorney proxy.
I would like to produce a 4-record dynaset as follows:

'79 VW John Q Owner 109 Lazy Lane Raleigh NC 27615
'79 VW Alfred Attorney 22 Main St Cary NC 27511
'79 VW ABC Loans 19 Castle Ave New York NY 00211
'79 VW Car Quest 5491 Minnesota Anchorage AK 99518

Is that even remotely possible? Here are table structures...

tblVehicles tblOwners tblProxies tblLienholders
[VehicleJobID] [OwnerID] [ProxyID] [LienHolderID]
[OwnerID] [OwnAddr] [ProxAddr] [VehicleJobID]
[ProxyID] blah... blah... [LHaddr]
[VIN] blah... blah... blah...
[MakeModel] blah... blah... blah...
blah...
blah...
blah...


Nov 13 '05 #6
MLH wrote:
Sounds like a plan. I'll have to read up a bin on union queries
a bit before starting. I'm not familiar with them.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
And don't discount what was said about multiple queries mentioned by
others. Create a base query (Q1) and then use Q1 in Q2, then Q3 in Q3.
It's fast, quick, works great.
Sounds possible, most likely using a 4-part union query. Each part
goes after one type of entity. I would recommend adding a column just
to identify the entitytype.

-Tom.
I have tblVehicles, tblOwners, tblProxies, tblLienholders.
In the vehicles table are [OwnerID] and [ProxyID] identifying
owner and proxy (generally an attorney). Vehicles table is
child table to tblOwners and tblProxies. tblLienholders has
[VehicleJobID] and is a child table to vehicles table.

As you can imagine, owners, proxies and lienholders houses
names & addresses of persons/companies. At some point, I need
to extract a dynaset of vehicles and these other entities -
each in a record by itself. For instance, for a given vehicle -
say their were 2 lienholders, an owner and an attorney proxy.
I would like to produce a 4-record dynaset as follows:

'79 VW John Q Owner 109 Lazy Lane Raleigh NC 27615
'79 VW Alfred Attorney 22 Main St Cary NC 27511
'79 VW ABC Loans 19 Castle Ave New York NY 00211
'79 VW Car Quest 5491 Minnesota Anchorage AK 99518

Is that even remotely possible? Here are table structures...

tblVehicles tblOwners tblProxies tblLienholders
[VehicleJobID] [OwnerID] [ProxyID] [LienHolderID]
[OwnerID] [OwnAddr] [ProxAddr] [VehicleJobID]
[ProxyID] blah... blah... [LHaddr]
[VIN] blah... blah... blah...
[MakeModel] blah... blah... blah...
blah...
blah...
blah...


Nov 13 '05 #7
MLH
Many thx to all of you. UNION SELECT works GREAT.
Nov 13 '05 #8
MLH <CR**@NorthState.net> wrote in
news:2k********************************@4ax.com:
I have tblVehicles, tblOwners, tblProxies, tblLienholders.
In the vehicles table are [OwnerID] and [ProxyID] identifying
owner and proxy (generally an attorney). Vehicles table is
child table to tblOwners and tblProxies. tblLienholders has
[VehicleJobID] and is a child table to vehicles table.


Seems to me like you have an erroneous schema.

You have vehicles and people. Put all the people in one table and
use an N:N join (with an intermediate table) to define what the
person's relationship to the car is. You'd then have:

tblVehicle : PK: VehicleID
tblPerson : PK: PersonID
tlbVehiclePerson : PK: VehicleID/PersonID (compound)

In tblVehiclePerson you'd have an additional field to define whether
that person is the owner, attorney or lien holder.

As lien holders are likely institutions, your person table may be
the wrong apporoach, and you'd need some generalized kind of
person/organization table. Of course, I often store organizations in
my people table, simply using the last name field as the entity
name.

But you really have relationships between two different distinct
entities, with one of those entities have 3 subtypes (owner,
attorney, lien holder). If your schema represents that, it's *much*
easier (and much more efficient) to get data about a vehicle's
related entities.

Another advantage is that a single person can then be related to
multiple vehicles. You could have the attorney's car, with an Owner
link, as well as the cars for which the attorney is the legal
represenative. And so forth.

The fact that this works shows that it's probably a much better
schema, whereas your schema requires putting the data about a single
person in more than one table. That's a clue right there that
there's something off with your underlying schema.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #9
MLH <CR**@NorthState.net> wrote in
news:qq********************************@4ax.com:
Many thx to all of you. UNION SELECT works GREAT.


Keep in mind that you can use UNION ALL to speed things up, as it
will not filter out duplicates (which you shouldn't have).

But I think your schema is wrong in the first place. You wouldn't
need a UNION if you used the right schema (I explained it in another
post).

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #10
MLH
You are probably on-the-money with those suggestions.
I was ill informed at the beginning - much needed design
level information didn't come to me until near the end of
the project. For instance, I had no idea I would need
proxies until a couple of days ago. And yes, I made
some decisions w/o thinking much about them. I do
like the vehicles 'n people clear distinction. I'll likely
clean this up in a future rev.
Nov 13 '05 #11
MLH <CR**@NorthState.net> wrote in
news:p0********************************@4ax.com:
You are probably on-the-money with those suggestions.
I was ill informed at the beginning - much needed design
level information didn't come to me until near the end of
the project. For instance, I had no idea I would need
proxies until a couple of days ago. And yes, I made
some decisions w/o thinking much about them. I do
like the vehicles 'n people clear distinction. I'll likely
clean this up in a future rev.


The great thing about that structure is that it easily supports the
addition of different subtypes in data without needing to add or
restructure tables.

Almost all of my apps are structured with some variation of the
people vs. all other entities. It just seems to me to be one of the
most common basic data schemas that it's just what I've settled on.

The only question in that schema is how you store addresses, and
then things can get really hairy.

But that's a separate issue entirely.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #12
MLH wrote:
I do
like the vehicles 'n people clear distinction. I'll likely
clean this up in a future rev.


Far, far better to do it now. People will get used to the way your app
works and worse, you'll get used to it. You'll never get around to
revising it. If you do, it will generate a tremendous amount of
headaches, because you'll have lots and lots data that may not fit as
easily into the properly designed schema David's suggested.

And an optimized design will allow you to add features much more easily
in the future.

Besides, nothing makes one's legacy stink as much people coming in
behind you to clean up messes. 8)

Don't settle on the design you have, you will ultimately regret it.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #13
On Wed, 28 Sep 2005 17:30:20 -0230, Tim Marshall
<TI****@PurplePandaChasers.Moertherium> wrote:

I second that.
-Tom.

MLH wrote:
I do
like the vehicles 'n people clear distinction. I'll likely
clean this up in a future rev.


Far, far better to do it now. People will get used to the way your app
works and worse, you'll get used to it. You'll never get around to
revising it. If you do, it will generate a tremendous amount of
headaches, because you'll have lots and lots data that may not fit as
easily into the properly designed schema David's suggested.

And an optimized design will allow you to add features much more easily
in the future.

Besides, nothing makes one's legacy stink as much people coming in
behind you to clean up messes. 8)

Don't settle on the design you have, you will ultimately regret it.


Nov 13 '05 #14

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

Similar topics

5
by: Abyss | last post by:
My view. anyone that doesn't like it tough, click off and stop reading it. I have spent the last 45 minutes reading through all the posts, and I believe that you have all missed the mark of...
2
by: PuckInLA | last post by:
I have a question. I have some data that I am pulling into a dataset that needs to have each row of data emailed out. I got the email funciton working great but its extracting that data that is...
4
by: frank | last post by:
Hi there. Before anyone gripes about cross posting, Ill say upfront that I just posted this message to am SQL server newsgroup because I want feedback from database developers as well as asp...
198
by: Sy Borg | last post by:
Hello: We are designing two multi-user client server applications that performs large number of transactions on database servers. On an average Application A has a 50% mix of select and...
4
by: sohendalski | last post by:
I have a report "Billing Period" and it runs off of 5 small queries "InvoiceQuery", "AdminQuery", "ProjManQuery", "InspectionQuery" and "ExpensesQuery". The InvoiceQuery has the information...
0
by: Jerms | last post by:
Hello all, I've been using this site quite a bit since starting my project and have found it very helpful. I have run into a roadblock though that I cant seem to scrounge up a solution to. I...
4
by: Ambpicard | last post by:
I am creating a database that will input customer information and part numbers. When I enter a prefix, I want access to look at a specific table and then when I enter the part number I want to to...
3
by: BobRoyAce | last post by:
I am using Visual Studio 2008 w/ VB.NET. For the database, I am using SQL Server 2005, which is running on a dedicated server box. I am creating a WinForms application for a client. It is run...
12
by: Alexnb | last post by:
This is similar to my last post, but a little different. Here is what I would like to do. Lets say I have a text file. The contents look like this, only there is A LOT of the same thing. () A...
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...
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
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...
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...

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.