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.

query question

167 100+
I am pulling my hair out trying to figure out how to make this work in a query so thought I would ask for any suggestions.
I have 2 queries, lets call one "Cats" and one "Dogs", the only key is "address". I am trying to build another query that will produce one row that combines the data results from both the "Cats" and "Dogs" queires. What I want to wind up with is a row of data for an address that has both "Cat" data and "Dog" data on it. In the situation I have, I have data in the "Cats" query when I run it separatly and no data in the "Dogs" query. So when I run the new query to combine the data, I get nothing. If I put data in the "Dogs" tables, I will get results, BUT, I will not always have data in both of them so I need to have the query.
I have tried a union of the 2 but that doesn't work because the data for each is different. Also, if I have "Cat" data but no "Dog" data, I get nothing. I want to get a row if I have either exist. It seems like it should be so simple, however, I just can't get the results I want. Hope this makes sense!!
Jun 11 '08 #1
5 1173
kcdoell
230 100+
Can you post the SQL of the "Dog" query and the SQL of the "Cat" query. It would make it easier to understand.

Best regards,

Keith.
Jun 11 '08 #2
ncsthbell
167 100+
Sorry, here is the sql (I used cars & boats instead!)
This is what I am currently trying, a union query but it is not giving the results I need.

The UNION query
SELECT Owner, Car, Mileage, Make, year, color, MPG
FROM qCars
SELECT Owner, Boat, Type, color, Year, seating, maxWeight
FROM qBoats


RESULTS of union query:
Owner Car Mileage Make Year Color Mpg
Me Honda 139000 Accord 2000 Black 24
Me Bayliner Sailboat Blue 1999 8 4000

Note - I want to get one row with both miles and fuel on the same line but you can see I am getting 2 rows and the 2nd row is really my fuel/gals but it is creating it as if it is mileage. Not sure if I can do this with the UNION statement????


These are results from each of the miles & fuel queries individually:
qCars
Owner Car Mileage Make Year Color Mpg
Me Honda 139000 Accord 2000 Black 24

qBoats:
Owner Boat Type color Year seating maxWeight
Me Bayliner SailBoat Blue 1999 8 4000
Jun 11 '08 #3
kcdoell
230 100+

RESULTS of union query:
Owner Car Mileage Make Year Color Mpg
Me Honda 139000 Accord 2000 Black 24
Me Bayliner Sailboat Blue 1999 8 4000

Note - I want .............
So I can understand, give me the result (the one row only..) that you thought the Union Qry would display using the above example........

Keith.
Jun 11 '08 #4
kcdoell
230 100+
So I can understand, give me the result (the one row only..) that you thought the Union Qry would display using the above example........

Keith.
Also take a look at this Building Union Queries. All the columns have to match in name and type to work correctly.....

It sounds like you want to merge data all into one row. If so, can you not start from scratch, by pulling both tables into a new query and then pulling in the fields that you are looking to populate?

Keith.
Jun 11 '08 #5
Hello,

I don't think that you need an union query. Both queries got the fieldname Owner. So make a new query with the two tables with an join on Owner. Select all the fields you needed and you you will get one row.

Query:
SELECT Boats.Owner, Boats.Boat, Boats.Type, Boats.Color, Boats.Year, Boats.Seating, Boats.MaxWeight, CARS.Car, CARS.Mileage, CARS.Make, CARS.Year, CARS.color, CARS.MPG
FROM Boats INNER JOIN CARS ON Boats.Owner = CARS.Owner;

Try this one.
Jun 22 '08 #6

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

Similar topics

9
by: majsen | last post by:
Hi, I have problem running this query. It will time out for me... My database are small just about 200 members. I have a site for swaping appartments (rental). my query should look for match in...
8
by: Együd Csaba | last post by:
Hi All, how can I improve the query performance in the following situation: I have a big (4.5+ million rows) table. One query takes approx. 9 sec to finish resulting ~10000 rows. But if I run...
3
by: John Ortt | last post by:
> I have a table of dates in ascending order but with varying intervals. I > would like to create a query to pull out the date (in field 1) and then pull > the date from the subsequent record...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
7
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
2
by: mmitchell_houston | last post by:
I'm working on a .NET project and I need a single query to return a result set from three related tables in Access 2003, and I'm having trouble getting the results I want. The details: ...
22
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for...
3
by: Richard Hollenbeck | last post by:
I am very sorry about the (almost) re-post, but you will see that my first question wasn't very clear; I have another question I posted this morning called, "in DAO: Run time error 3061 Too few...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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.