Hi, i am still stuck in SQL query about how to retrieve data from two tables.
I have two database tables- Forecast

TimeStamp            | Temperature | Rainfall | Wind | City_Code
2011-03-13 10:00:00  |22.2 (degC)  |  0      |   7   |  1
2011-03-13 11:00:00  |23.1 (degC)  |  0      |   6   |  1        

and Tower

TimeStamp            | Temperature | Rainfall | Wind | Tower_name
2011-03-13 10:00:00  |19.5 (degC)  |  0      |   7   |  NAP
2011-03-13 11:00:00  |18.9 (degC)  |  0      |   6   |  NAP        

Now i need to retrieve the data from the two tables. How to do it? i need to display according to current TimeStamp. I know the sql query how to retrieve whole data according to current date and time from one table---

SELECT * from tower
 WHERE TimeStamp >= DATEADD(DD,datediff(DD,0,getdate()),0)
 AND TimeStamp < DATEADD(dd, datediff(dd, 0,getdate()) + 1,0)

But i could not able to apply for the two tables. Please give me some suggestion. Thanks in advance.

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

7 Years
Discussion Span
Last Post by debasisdas

Thank you for your quick reply. Actually i need to compare the datas from two tables.
I need to display them as

TimeStamp  | Temperature     |    Rainfall       |
           |Forecast| Tower  |forecast |   Tower |

I need to have only 1 time column and according to the current time and date i need to display them as above........

Edited by Ezzaral: Added code tags for formatting.


Actually the fields of the two tables are same and they are in 1:1 relation. I just need to query and display them.


Yaa! i have done it just included in the where clause one more thing that TimeStamp of Forecast table is equal to TimeStamp of Tower table.


Joining tables on time / timestamp is not the best of options to go with.

You may need to consider re-designing your database table structures.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.