469,125 Members | 1,778 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,125 developers. It's quick & easy.

Join Of 2 Tables

21
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.
Dec 8 '06 #1
3 1408
ronverdonk
4,258 Expert 4TB
Using a left JOIN will give the result, where the columns of table2 that are not in table1 will be NULL.
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM table1 LEFT JOIN table2 USING (col1)
produces result:
Expand|Select|Wrap|Line Numbers
  1. +------+------+
  2. | col1 | col2 |
  3. +------+------+
  4. |    1 | NULL |
  5. |    2 | NULL |
  6. |    3 |    4 |
  7. |    4 | NULL |
  8. |    5 | NULL |
  9. |    6 | NULL |
  10. |    7 | NULL |
  11. +------+------+
Ronald :cool:
Dec 8 '06 #2
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.
Dec 25 '06 #3
ronverdonk
4,258 Expert 4TB
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:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM table WHERE createdon < CURRENT_DATE;
Ronald :cool:
Dec 25 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by Matt | last post: by
4 posts views Thread by Anthony Robinson | last post: by
2 posts views Thread by dskillingstad | last post: by
2 posts views Thread by Bennett Haselton | last post: by
7 posts views Thread by Shanimal | last post: by
3 posts views Thread by Zeff | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.