Reputation: 1033
Support I have multiple tables (X,Y,Z) of the exact same structure. The tables have a DATETIME field and a DATA field. I want to extract and compare DATA values based on the same DATETIME for all tables. Assuming all tables have the same DATETIME values but different data. What would the SQL statement be?
I can't get it to work. Here are tables:
Table: A
Table: B
Table: C
Structure for all tables are the same. I want to retrieve data from all tables where their datetime are same.
Upvotes: 1
Views: 53
Reputation: 459
I'll post a new answer, seeing that your question changed. You need to perform a join between those tables:
SELECT * FROM
(A JOIN B ON A.datetime = B.datetime)
JOIN C ON B.datetime = C.datetime
That will create a table with columns:
datetime | A.high | A.low | B.high | B.low | C.high | C.low
Upvotes: 0
Reputation: 459
This sounds like a case for the JOIN operator.
SELECT * FROM X JOIN Y ON X.datetime = Y.datetime JOIN Z on Y.datetime = Z.datetime
This should give you rows with one datetime column and X.data, Y.data and Z.data columns.
Upvotes: 1