2012-03-13 11 views
0

mysqlクエリ(phpを使用)を使用して、各テーブルを一度に1つずつ検索し、キーの日付と一致しないすべての結果のみを表示しますt_lastmodテーブルに格納されます。私はtablename = fieldの値をONにする方法がわかりません。フィールド名に等しいテーブル名にSQL JOINを入力

t_one

guid | name | lastmod 
1 | Joe | 2012-01-01 01:00:00 
2 | Tom | 2012-01-02 01:00:00 
3 | Sue | 2012-03-01 02:00:00 

t_two

guid | pet | lastmod 
4 | cat | 2012-01-01 01:00:00 
5 | dog | 2012-01-02 01:00:00 
6 | fish | 2012-03-01 02:00:00 

t_three

guid | fruit | lastmod 
7 | orange | 2012-01-01 01:00:00 
8 | pear | 2012-01-02 01:00:00 
9 | grape | 2012-03-01 02:00:00 

t_lastmod

table_name | lastmod 
    t_one | 2012-01-01 01:00:00 
    t_two | 2012-01-02 01:00:00 
    t_three | 2012-01-01 02:00:00 

クエリの結果は次のようになります。

t_one => 2 | Tom | 2012-01-02 01:00:00 
t_one => 3 | Sue | 2012-03-01 02:00:00 
t_two => 4 | cat | 2012-01-01 01:00:00 
t_two => 6 | fish | 2012-03-01 02:00:00 
t_three => 8 | pear | 2012-01-02 01:00:00 
t_three => 9 | grape | 2012-03-01 02:00:00 

私のコード今のところ(t_lastmod ON JOINの上の助けが必要...)

$tables = array('t_one', 't_two', 't_three'); 

    foreach ($tables AS $table) { 

    $query = " select $table.* from $table JOIN t_lastmod ON $table = t_lastmod.TABLE_NAME WHERE $table.lastmod != t_lastmod.lastmod "; 

    } 
+0

クエリの現在の出力は何ですか? –

答えて

1
select $table.* 
from $table 
JOIN t_lastmod ON '$table' = t_lastmod.TABLE_NAME 
WHERE $table.lastmod != t_lastmod.lastmod " 
+0

ON句に$ tableを一重引用符で囲みます。ありがとう。 – Vikram

+0

ありがとう。それは簡単だった:) – Jeffrey

関連する問題