Help JOINS!!

  • I am having a problems with creating a join between 2 tables these are their formats

    table1, col1 int, col2 char(1), col3 int, col4 int

    table2, col1 varchar(10), col2 varchar(100)

    i want to join col2, col3 from table1 on col1, col2 from table2

    table2 could has nulls which i want to see

  • Really not sure based solely on your post what you are looking for here. To help us inderstand better it would help if you provided more information. Please read and following the guidelines for posting questions as shown in the first article I have referenced below in my signature block regarding asking for assistance.

  • table1

    col1 col2 col3 col4

    --------------------

    --1---C---100---null

    --2---D---200---1

    table2

    col5 col6

    ----------

    Drive---D

    null----null

    i want the 2 table joint to look like this in the results

    col2 col3 col5 col6

    ---------------------

    --C---100---Drive---C

    --D---200---null---null

  • glugingboulder (7/29/2009)


    table1

    col1 col2 col3 col4

    --------------------

    --1---C---100---null

    --2---D---200---1

    table2

    col5 col6

    ----------

    Drive---D

    null----null

    i want the 2 table joint to look like this in the results

    col2 col3 col5 col6

    ---------------------

    --C---100---Drive---C

    --D---200---null---null

    I'm sorry, but I just don't see a relationship between the data in the two tables. Please read and follow the instructions in the article I recommended that you read. Based on these posts, I am really having a hard time trying to figure out what you are attempting to accomplish.

  • ok sorry about the poor formatting.

    Basically i need to combine data from 2 tables into 1 that have no relationship to each other. It will transfered to a monitor server where the data will be emailed out, so even though the table data has no relationship its is still useful information, what would be the best way to acomplish this?

  • You should not be joining on columns that contain Nulls, because, except for certain functions like IsNull(), any expression containing a null value evaluates to null under ANSI Standards. Your sample shows a row that consists entirely of Nulls.

    I think what you actually want is a LEFT OUTER JOIN, which will produce a null for each column from the right table in the select list where the join conditions do not find a match in the right table. NOTE: the Nulls do not exist in the right table; the join produces those values.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • What do you mean by no relationship? Based on which columns are you looking for relationship or no relationship between the tables?

  • glugingboulder (7/29/2009)


    ok sorry about the poor formatting.

    Basically i need to combine data from 2 tables into 1 that have no relationship to each other. It will transfered to a monitor server where the data will be emailed out, so even though the table data has no relationship its is still useful information, what would be the best way to acomplish this?

    If they have no relation to each other, they don't belong in the same table. Send two different tables. Why try to force a relationship where none exists?

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • How about showing us what you are actually working. Give us the DDL (CREATE TABLE statements) for the tables, sample data for the tables, and the expected results based on the sample data.

    Follow the guidelines presented in the first article referenced in my signature block regarding asking for assistance. If you follow those guidelines, you will get much better answers to your questions.

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply