For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > January 2005 > INSERT with SELECT query









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author INSERT with SELECT query
djordj

2005-01-22, 8:55 am

I've got two tables.

TBL_RTDATA (ID, stID, T, p, datetime)
TBL_DATA (stID, tmax, slp)

In TBL_RTDATA I've got several observation recorderd every 10 minutes.
Example:
1, 1, 10, 1000, 10:00
2, 1, 11, 1000, 10:10
3, 1, 12, 1003, 10:20
4, 1, 11, 1004, 10:30
5, 1, 14, 1002, 10:40
6, 1, 13, 1000, 10:50
7, 2, 14, 1000, 10:00
8, 2, 13, 1000, 10:10
9, 2, 17, 1002, 10:20
10, 2, 15, 1020, 10:30
11, 2, 14, 1032, 10:40
12, 2, 18, 1022, 10:50

In TBL_DATA I've got to put the greatest value for TBL_RTDATA.T and the
value of p taken at a specific time (for example 10:30).

I've done an INSERT...SELECT query as follows:
INSERT INTO TBL_DATA (stID, tmax, p) SELECT TBL_RTDATA.stID as stID,
max(TBL_RTDATA.T), ?????? FROM TBL_RTDATA GROUP BY stID

Everything works fine but I can't get p value taken for a specific time.
Is it possibile to achieve this with just one query?
What do I have to specify in place of "??????" the get the TBL_DATA.p WHERE
TBL_RTDATA.datetime = "10:30"?

Thanks!
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com