2016-06-30 17 views
1

に参加使用せずに、複数のテーブルから選択し、組合:私は次のSQLクエリを持って

SELECT t1.id as id, 
     t1.username as username, 
     CONCAT_WS(' ', t2.ad,t2.soyad) as fullname, 
     t2.title as title, 
     t3.pass as password, 
     t3.phone_login as hat, 
     t2.time as date 
FROM kullanici t1, kullanici_tanim t2, dial_users t3 
WHERE t1.id = t2.usr_id AND t1.agent_id = t3.user_id 
GROUP BY t1.id 
ORDER BY t1.id ASC 

このクエリは正常に動作します。私はジョインを使うべきですか?正しい方法は何ですか?

+0

「JOIN's;あなたは技術的にはすでにWHERE句の条件を満たしていますが、あなたは古いやり方でそのようにしています。 – Uueerdo

+0

Aaron Bertrandさんは、「JOIN」擬似体の使用を促進すると、アーロン・バートランドは素晴らしい記事を書いています。[古い習慣を使って蹴る悪い習慣](http: /sqlblog.com/blogs/aaron_bertrand/archive/2009/10/08/bad-habits-to-kick-using-old-style-joins.aspx)を参照してください。 –

+0

でも両方とも同じ結果が得られます。ここではJoin条件を使用して、どこで条件を指定しますか?「GROUP BY t1.id」を削除すると、結合条件として必要な列をフィルタリングします。 – mohan111

答えて

0

ANSI-92-compliant codeの場合、結合を使用します。例:

SELECT t1.id as id, 
      t1.username as username, 
      CONCAT_WS(' ', t2.ad,t2.soyad) as fullname, 
      t2.title as title, 
      t3.pass as password, 
      t3.phone_login as hat, 
      t2.time as date 
FROM kullanici t1 
    INNER JOIN kullanici_tanim t2 
    ON t1.id = t2.usr_id 
    INNER JOIN dial_users t3 
    ON t1.agent_id = t3.user_id 
GROUP BY t1.id 
ORDER BY t1.id ASC 
+0

すべての行を2回取得します。どのようにしてグループ化せずにすべてのIDのための1つを得ることができますか? – Invictus26

+0

なぜGROUP BYを使用しないのですか? – bernie

+0

グループなしで行ごとに1つの結果しか得られないかどうかを知りたいですか? – Invictus26

関連する問題