How to use SQL query to list all customers from both tables including duplicates?

MissyMadi2
MissyMadi2 used Ask the Experts™
on
Experts,

I am testing the following sql query to see if I can pull all Animals from two tables including dups

Table 1                            Table 2
C_ID     Animal             C_ID    Animal
1          A_Ant                 1         A_Ant
2          B_Bear               2         Z_Zebra
3          C_CAT                 3         T_Tiger
4          D_DOG               4        D_Dog
5          E_elephant         5         S_Snake


Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
select * from table_1 t1 inner join table_2 t2 on ucase(t1.animal)=ucase(t2.animal)
Commented:
do you mean this out put?
A_Ant
B_Bear
C_CAT
D_DOG
E_elephant
A_Ant
Z_Zebra
T_Tiger
D_Dog
S_Snake

then try this

Select Animal from table1 union all Select Animal from table2
ramromconsultant

Commented:
Please learn how to ask good questions. You refer to "following sql query" but there is none. It would also be nice to see the output you desire. Please don;t make us guess.
Your question title refers to Customers rather than animals. All very confusing.

The more explicit and accurate you are the easier it is for us to help.

Author

Commented:
First off, I hit submit before I entered the query....so calm down ramrom.  My apolgies, it was late.

Here is what I had for the query:

Select table_a.animal, table.b_animal
FROM table.a INNER JOIN table.b ascending

The output I'm looking for is

A_Ant
A_Ant
B_Bear
C_CAT
D_DOG
D_Dog
E_elephant
S_Snake
T_Tiger
Z_Zebra

in alphbetical order
new at this so wondering when to use INNER JOIN and union.

Thanks, Missymadi
In this case you need to use UNION ALL, not UNION. And just add order by at the end

select animal from table1
union all
select animal from table2
order by animal


http://msdn.microsoft.com/en-us/library/ms180026.aspx

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial