Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Join table

Posted on 2011-04-22
5
Medium Priority
?
326 Views
Last Modified: 2012-05-11
Good morning,
Ive done this before, but cant remember how Ive done it.

Ive for 2 tables with the same field name, but with different values in, Id like to create a query which displays all rows from one table, and in the same coloum the data from the second.

The coloum name is 'sqlOut' and the tables are imaginativly called 'table1' and 'table2', I thought I could just use join, but I dont have anything to join onto.

Any suggestions?

Thank you
0
Comment
Question by:tonelm54
5 Comments
 
LVL 9

Expert Comment

by:kaminda
ID: 35446742
You could use UNION ALL to do this
SELECT sqlOut FROM Table1 
UNION ALL
SELECT sqlOut FROM Table2

-- Also you can use UNION which will eliminate any duplicates in the final result

SELECT sqlOut FROM Table1 
UNION
SELECT sqlOut FROM Table2

Open in new window

0
 
LVL 22

Accepted Solution

by:
Om Prakash earned 1000 total points
ID: 35446745
If there is no relation between the tables then you can use union. Example:

SELECT sqlOUT from table1
union
SELECT sqlOUT from table2
0
 
LVL 4

Assisted Solution

by:malikirfan28
malikirfan28 earned 1000 total points
ID: 35446869
You can get data from both table in one column by using "UNION" or "UNION ALL".

UNION will return only distinct records whereas "Union All" will return the complete table records (including some duplication if exist).

So here will be your query.

Select sqlOut from table1
UNION --(OR UNION ALL)
Select sqlOut from table2

0
 
LVL 9

Expert Comment

by:kaminda
ID: 35446910
malikirfan28:

Its a pain when you post the same answer isnt it?
0
 
LVL 1

Expert Comment

by:jesusaflores
ID: 35446983
If you need to show data for column 'sqlOut' in both tables, then you help with the UNION ALL statement, but if you want to search from one table to another you should use LEFT JOIN or RIGHT JOIN.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question