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

Query to show all records, but combine those that match?

I am trying to combine the data from two similar tables into one
query, but I need for all of the records from both tables to show up
and I want the ones that have matching 'emplid' to be combined into
one record showing both the 'empstatus' and 'strole' fields.

The following query works, but does not combine the matching records:

SELECT givenname, sn, empstatus, emplid, ssn FROM dbo_EmpData
WHERE empstatus='A'
UNION ALL SELECT givenname, sn, strole, emplid, ssn FROM dbo_StdData
WHERE strole='untst';

The fields 'empstatus' and 'strole' become one field 'empstatus' when
the query is run. This field displays both 'A' and 'untst' in the
query result and I assume that is why it is not combining the matching
records. I would like it to show the following results:

givenname sn empstatus strole emplid ssn

Instead I get:

givenname sn empstatus emplid ssn
Any ideas on how I can change the query to fix this?

Thank you in advance for any help!

- Craig
Nov 13 '05 #1
1 2967
ct******@earthling.net (snOOp) wrote in
news:1f**************************@posting.google.c om:
I am trying to combine the data from two similar tables into
one query, but I need for all of the records from both tables
to show up and I want the ones that have matching 'emplid' to
be combined into one record showing both the 'empstatus' and
'strole' fields.

The following query works, but does not combine the matching
records:

SELECT givenname, sn, empstatus, emplid, ssn FROM dbo_EmpData
WHERE empstatus='A'
UNION ALL SELECT givenname, sn, strole, emplid, ssn FROM
dbo_StdData WHERE strole='untst';

The fields 'empstatus' and 'strole' become one field
'empstatus' when the query is run. This field displays both
'A' and 'untst' in the query result and I assume that is why
it is not combining the matching records. I would like it to
show the following results:

givenname sn empstatus strole emplid ssn

Instead I get:

givenname sn empstatus emplid ssn
Any ideas on how I can change the query to fix this?

Thank you in advance for any help!

- Craig


A single query will be quite messy.Your key field on each table
is emplid, I assume.
Create the union query with only this field.

SELECT emplID FROM dbo_EmpData where empstatus = 'A'
UNION SELECT emplID FROM dbo_StdData WHERE strole='untst'

Don't use the ALL keyword, we only need one emplid.

Now create your second query that starts with the union and left
joins the two tables. Create calculated fields that use an
nz[empdata].[givenname],dbo_StdData.[givenname]) type construct
for each of the common fields, plus the two independent fields.

--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #2

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

Similar topics

6
by: paii | last post by:
I have a table that stores job milestone dates. The 2 milestones I am interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18....
5
by: Bob Weisenburger | last post by:
I have a table of "memos". each record in that table has a primary key "memo ID" that is autonumber. I have another table that is "memo receipts" with each record having a "receipt id" field that...
4
by: Apple | last post by:
1. I want to create an autonumber, my requirement is : 2005/0001 (Year/autonumber), which year & autonumber no. both can auto run. 2. I had create a query by making relation to a table & query,...
14
by: Darin | last post by:
I have a table that I want to delete specific records from based on data in other tables. I'm more familiar with Access '97, but am now using 2003, but the database is in 2000 format. In '97, I...
2
by: Thomas | last post by:
Hi All. I think that if I explain the database layout first it may be easier to ask my question. Table Name Field Name Test TestCode Description SpecimenRequirements FeeSchedule TestCode...
5
by: DougieC | last post by:
Hello all. First off, Im not a programmer so I am some what stumbling through this. 8 years of social science education never trained me to handle real world problems, such as figuring out how to...
4
by: ilikebirds | last post by:
SO table tqcmain1 has 26 records. My goal is to Show all of the tqcmain1 data with the employee_id from MakeUnion90days where the order_number and step_found match. So ideally I want the...
9
by: Sinner | last post by:
Hi, I have a field name 'USER' in tableMAIN. How do I replace the user names with corresponding user names. I can do that in xl using vlookup but now I'm trying to find a way to do that in...
2
by: nspader | last post by:
OK, I am pulling my hair out on this one. It seems like it should be so simple and I cannot seem to find the answer. I am using Access 2000 on Windows 2000. I have two tables set up. Table...
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
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: 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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.