Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Duplicate Results with union query?

Author  Topic 

louiedogg418
Starting Member

28 Posts

Posted - 2011-04-20 : 11:08:58
So the fallowing is my code for table create, table population and union query... but u get double results when i run my union query, but i dont know why?


create table Employee_1
(Emp_id int primary key,
First_name char (25),
Last_name char (50),
Phys_add char(75),
City char (25),
State char (20),
Area_code char (3),
Tel_num char (8),
Emp_EEO char (25),
Hire_date date,
Sal dec (15,2),
Sex char (1),
Age char (3),
Job_id int)


create table Employee_2
(Emp_id int primary key,
First_name char (25),
Last_name char (50),
Phys_add char(75),
City char (25),
State char (20),
Area_code char (3),
Tel_num char (8),
Emp_EEO char (25),
Hire_date date,
Sal dec (15,2),
Sex char (1),
Age char (3),
Job_id int)

Create table Job_Title
(Job_id int primary key,
Emp_EEO char (50),
Job_title char (50),
Job_dis char(256),
Exempt_stat char (10))





insert into Employee_1
(Emp_id,first_name, Last_name, Phys_add, City, State, Area_code, Tel_num, Emp_EEO, Hire_date, Sal, Sex, Age, Job_id)
values
(1,'Glenn','Edelman','175 Bishop Lane','La Jolla','California','619','555-0199','Sales Workers','10/7/2003','21500.00','M','64','4'),
(2,'Eric', 'McMullen','763 Church Street', 'Lemon Grove', 'California','619', '555-0135', 'Sales Workers', '11/1/2002', '13500.00', 'M', '20','3'),
(3,'Raj','Slentz','123 Torrey Drive','North Clairmont','California','619','555-0123','Officials and Managers','6/1/2000','48000.00','M','34','2'),
(4,'Erin','Broun','2045 Parkway Apt 2B','Encinitas','California','760','555-0100','Sales Workers','3/12/2003','10530.00','F','24','3'),
(5,'Donald','Carpenter','927 Second Street','Encinitas','California','760','555-0154','Office/Clerical','11/1/2003','15000.00','M','18','9'),
(6,'David','Esquivez','10983 North Coast Hwy Apt 902','Encinitas','California','619','555-0108','Operatves','7/25/2003','18500.00','M','25','8'),
(7,'Nancy','Sharp','10793 Montecino Road','Romona','California','858','555-0135','Sales Workers','7/12/2003','21000.00','F','24','4')



insert into Employee_2
(Emp_id,first_name, Last_name, Phys_add, City, State, Area_code, Tel_num, Emp_EEO, Hire_date, Sal, Sex, Age, Job_id)
values
(1,'Juanita','McNamara','923 Parkway','Loway','California','619','555-0200','Office/Clercial','10/29/1999','25500.00','F','32','1'),
(2,'Meredith','Nguyen','10583 Arenas Street','La Jolla','California','619','555-0102','Technician','9/27/1998','43000.00','F','25','5'),
(3,'Stephen','Harvey','7863 High Bluff Drive','La Jolla','California','619','555-0123','Officials and Managers','3/1/1998','75000.00','M','51','6'),
(4,'Matthew','Vu','981 Journey Piers','La Gilla','California','619','555-0138','Technician','8/16/2000','37000.00','M','26','5'),
(5,'Ledonna','Avery','198 Governor Drive','Del Mar','California','619','555-9135','Craft Workers','3/28/2003','21000.00','F','23','7'),
(6,'Craig','Drohos','Solano Beach','Solano Beach','California','619','555-0202','Officials and Managers','6/15/2000','51000.00','M','32','2'),
(7,'Ealine','Meier','0703 Drehidl Lane','Del Mar','California','858','355-0112','Sales Worker','9/10/2000','20500.00','F','51','4'),
(8,'Stanley','Quillian','98542 Wandering Road Apt 2B','Del Mar','California','760','555-0198','Operatives','12/16/1999','23000.00','M','29','8'),
(9,'Thomas','Tyink','87592 Pacific Heights Boulevard','Del Mar','California','858','555-0159','Craft Workers','5/1/2001','19000.00','M','32','7'),
(10,'Brent','Vance','927 Cynthia Lane','Parkway','California','838','555-0147','Sales Workers','3/29/2001','10530.00','M','22','3')




insert into Job_Title
(Job_id,Emp_EEO, Job_title, Job_dis, Exempt_stat)
values
(1,'Office/Clercial','Accounting','Maintains Accoutning Records','Non-Exempt'),
(2,'Officials/Managers','Assistant Manager','Assists store manager in daily operations of store','Exempt'),
(3,'Sales Workers','Baggers','Places customer orders in bags','Non-Exempt'),
(4,'Sales Workers','Cashier','Operates cash register','Non-Exempt'),
(5,'Technician','Computer Support Specialist','provides technical assistance and training to system
users','Non-exempt'),
(6,'Officials/Managers','Dir. of Finance/Acc','Directs Finances and accounting','Exempt'),
(7,'Craft Workers','Asst. bakery/pastry','prepares food items','Non-exempt'),
(8, 'Oppertative','Asst. Butcher','prepares food items','Non-Exempt'),
(9, 'Office/Clercial','Stocker','Stores, prices and restocks merchandise','Non-Exepmt')





select * from employee_1
union
select * from employee_2

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2011-04-20 : 11:12:06
But output rows are distinct. Do you mean duplicate EmpID ??


--------------------------
http://connectsql.blogspot.com/
Go to Top of Page
   

- Advertisement -