2016-11-02 19 views
-2

Mysql。リンク2つのテーブル、table1は労働者、table2は会社です。 表1約50,000レコードおよび表2約15,000レコード。リンクテーブルの内部結合を使用します。未知の入力メールに対しては機能しません。 私は会社から、または従業員から電子メールで申し出ます。 emailWまたはemailF(変数 "$ W_EMAIL") (会社からの電子メールまたは労働者からの電子メールのポストを知っていれば、requestXの値を見つけます。値 - プログラムは応答していません...)mysql内部結合テーブル1とテーブル2

TABLE_1

id  | emailW 
------ | ------ 

100 | "[email protected]" 
100 | "[email protected]" 
100 | "[email protected]" 

Table_2

id  | requestF  | emailF 
------ | ------------- | ------ 
100 | "service xx" | "[email protected]" 
200 | "service xx" | "[email protected]" 
300 | "service zz" | "[email protected]" 

BBBBする@ BBを見つけた場合.com ... ok(電子メールはWORKERSに存在します)
find [email protected] ... ok(電子メールは会社にあります)
見つけた場合は[email protected] ...応答なし...エラーなし... "白い画面"! (電子メールが存在しない場合!)

マイコード:

SELECT table1.id, 
     table1.emailW, 
     table2.id, 
     table2.requestF, 
     table2.emailF    
    FROM table1 
INNER JOIN table2 ON table1.id = table2.id 
WHERE table1.emailW='$W_EMAIL' 
    OR table2.emailF='$W_EMAIL' 
+1

」?この質問は完全な混乱であり、完全に判読できません。私たちは喜んでお手伝いしますが、問題を実際に説明する必要があります。ランダムにキーボードを叩くことは、質問することと同じではありません。 – David

+0

@David、あなたは信じられないほど穏やかでした。 – FDavidov

+0

私の英語は良くありません。プログラムコードは読み取り可能で、テーブル1と2の既存の電子メールで動作します。動作しません - テーブル1,2の電子メールに対する応答がありません。 "ホワイトスクリーン"のみです。テーブル2の電子メールは正しいです[email protected] ... for id = 100 –

答えて

0
select case when t.obs > 0 then 'Ok' else 'Not Ok' end as 'OKorNotOk' 
from 
(
select s.*,count(*) Obs 
from 
(
SELECT table_1.id, 
     table_1.emailW, 
     table_2.id t2id, 
     table_2.requestF, 
     table_2.emailF    
    FROM table_1 
left join table_2 ON table_1.id = table_2.id 
union 
SELECT table_1.id, 
     table_1.emailW, 
     table_2.id , 
     table_2.requestF, 
     table_2.emailF    
    FROM table_1 
right join table_2 ON table_1.id = table_2.id 
) s 
where s.emailw = '[email protected]' or s.emailf = '[email protected]' 
) t 

結果

+-----------+ 
| OKorNotOk | 
+-----------+ 
| Ok  | 
+-----------+ 
1 row in set (0.00 sec) 

それとも

select t.emailtofind, 
      s.id,s.requestf, 
      case when s.srce = 't1' then 'y' else '' end as 'ok found in t1', 
      case when s.srce = 't2' then 'y' else '' end as 'ok found in t2', 
      case when s.email is null then 'Not Found' else 'Ok' end as Message 
from 
(
select 't1' as srce,t1.ID,'' as requestf , t1.emailw email from table_1 t1 
union 
select 't2',t2.ID,t2.requestf , t2.emailf from table_2 t2 
) s 
right join (select cast('[email protected]' as char(20)) as emailtofind) t on t.emailtofind = cast(s.email as char(20)) 

結果

+-------------+------+------------+----------------+----------------+---------+ 
| emailtofind | id | requestf | ok found in t1 | ok found in t2 | Message | 
+-------------+------+------------+----------------+----------------+---------+ 
| [email protected] | 100 | service xx |    | y    | Ok  | 
+-------------+------+------------+----------------+----------------+---------+ 
1 row in set (0.00 sec) 
+0

残念ながら、それは私のために非常に複雑です。私はこれを理解していない。 "私はあなたがこれで何をexatcly意味するかわからない" –

+0

私のために3つの亜種すべての結果は重要です:[email protected] ... [email protected] ... [email protected] = print:見つけたり見つけたりしない –

+0

同じ質問で3つのメールを検索したいですか? $ W_emailはどこから来たのですか? –

関連する問題