Join Of 2 Tables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • geek491
    New Member
    • Oct 2006
    • 21

    Join Of 2 Tables

    HI

    I have 2 tables.

    table1 has all dates from DAY1 - DAY7

    COL1
    ---------
    DAY1
    DAY2
    DAY3
    DAY4
    DAY5
    DAY6
    DAY7



    Table2 has effort entry and a date entry like this
    COL1 COL2
    ----------------------------
    DAY3 4

    Now i need a SQL that will JOIN these 2 tables and produce the output as

    COL1 COL2
    ----------------------------
    DAY1 0
    DAY2 0
    DAY3 4
    DAY4 0
    DAY5 0
    DAY6 0
    DAY7 0


    So if no days exist in table2 the value field should be filled with 0.
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Using a left JOIN will give the result, where the columns of table2 that are not in table1 will be NULL.
    Code:
    SELECT * FROM table1 LEFT JOIN table2 USING (col1)
    produces result:
    Code:
    +------+------+
    | col1 | col2 |
    +------+------+
    |    1 | NULL |
    |    2 | NULL |
    |    3 |    4 |
    |    4 | NULL |
    |    5 | NULL |
    |    6 | NULL |
    |    7 | NULL |
    +------+------+
    Ronald :cool:

    Comment

    • sravanpalakala
      New Member
      • Dec 2006
      • 1

      #3
      Hi !

      Can you help me out . I have a table with set of columns, one of the column is createdon . Now i need to compare createdon column with sysdate. if it is less than sysdate i need to fetch all columns and display.
      my createdon is created in database as datetime in mysql .can u give me a query to compare created on and system date.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Originally posted by sravanpalakala
        Hi !

        Can you help me out . I have a table with set of columns, one of the column is createdon . Now i need to compare createdon column with sysdate. if it is less than sysdate i need to fetch all columns and display.
        my createdon is created in database as datetime in mysql .can u give me a query to compare created on and system date.
        This question has nothing to do with the title of this thread. So members who lookup thsi forum, based on the thread title, will not see your post. Please open a new thread if you have a new question that has no relation to the title.

        For now the statement is:
        Code:
        SELECT * FROM table WHERE createdon < CURRENT_DATE;
        Ronald :cool:

        Comment

        Working...