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.

Recommended Answers

All 6 Replies

What is the relation between these two tables ?

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........

that did not answer my question.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.