Join table

Posted on 2011-04-22
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
Question by:tonelm54
    LVL 9

    Expert Comment

    You could use UNION ALL to do this
    SELECT sqlOut FROM Table1 
    SELECT sqlOut FROM Table2
    -- Also you can use UNION which will eliminate any duplicates in the final result
    SELECT sqlOut FROM Table1 
    SELECT sqlOut FROM Table2

    Open in new window

    LVL 22

    Accepted Solution

    If there is no relation between the tables then you can use union. Example:

    SELECT sqlOUT from table1
    SELECT sqlOUT from table2
    LVL 4

    Assisted Solution

    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
    Select sqlOut from table2

    LVL 9

    Expert Comment


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

    Expert Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
    Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
    Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now