我有兩個MySQL查詢如下我如何組合兩個mysql查詢來獲得單個結果?
SELECT cv_requirement,cv_target,cv_target_date_for
FROM `cv_target`
where cv_target_date_for between '2014-02-20' and '2014-02-27' and cv_recruiter='44'
AND
select count(candidate_id)as achi,cv_target_date from candidate
where fk_posted_user_id='44'
and cv_target_date between '2014-02-20' and '2014-02-27'
group by fk_job_id,cv_target_date
第一查詢產生11 record
,第二個顯示10 record
我怎麼可以結合這兩個查詢,以獲得單個查詢結果顯示11 record with 10 values and 1 null value
我曾嘗試這但只顯示10 record not null record
SELECT cv_requirement,cv_target,cv_target_date_for,count(candidate_id) achi, cv_target_date
FROM `cv_target` a
left join candidate b
on a.cv_requirement=b.fk_job_id and a.cv_target_date_for=b.cv_target_date
where cv_target_date_for between '2014-02-20' and '2014-02-27' and cv_recruiter='44'
group by cv_requirement,cv_target
query one
fk_job_id achi cv_target_date Ascending
188 1 2014-02-20
220 1 2014-02-20
220 1 2014-02-21
221 5 2014-02-21
224 1 2014-02-22
224 2 2014-02-24
224 2 2014-02-25
222 1 2014-02-25
222 3 2014-02-26
224 1 2014-02-27
query two
cv_requirement cv_target cv_target_date_for
188 2 2014-02-20
220 2 2014-02-21
221 2 2014-02-21
224 3 2014-02-22
220 1 2014-02-22
224 2 2014-02-24
222 1 2014-02-24
224 4 2014-02-25
222 4 2014-02-25
222 3 2014-02-26
224 3 2014-02-27
i want this out put
cv_requirement cv_target cv_target_date_for achi
188 2 2014-02-20 1
220 2 2014-02-21 1
221 2 2014-02-21 5
224 3 2014-02-22 1
220 1 2014-02-22 0
224 2 2014-02-24 2
222 1 2014-02-24 0
224 4 2014-02-25 2
222 4 2014-02-25 1
222 3 2014-02-26 3
224 3 2014-02-27 1
請提供一些幫助。
您可以使用union。請看這裏stackoverflow.com/questions/5331808/how-do-i-combine-the-results-of-two-queries-with-ordering – bring2dip
@avisheks我已經添加了兩個表查詢輸出和結果輸出,我想請幫助 – user3364940
使它正確的外部加入 – avisheks