Nyob qhov twg vs koom kev ua tau zoo?
Nyob qhov twg vs koom kev ua tau zoo?

Video: Nyob qhov twg vs koom kev ua tau zoo?

Video: Nyob qhov twg vs koom kev ua tau zoo?
Video: Nkauj tawm tshiab _QHov twg los tau _ by Xim vaj & Xeeb vwj & xis nus vaj _ (2020 - 2021 ) 2024, Kaum ib hlis
Anonim

Feem ntau, EXISTS los yog Koom yuav ua tau ntau npaum li cas (thiab sai) dua li ib nqe lus IN. Nrog ib EXISTS los yog a Koom , cov ntaub ntawv yuav rov qab muaj tseeb / cuav thaum tshawb xyuas qhov kev sib raug zoo tau teev tseg. Tshwj tsis yog tias lub rooj hauv cov lus nug me me, EXISTS los yog Koom yuav ua tau zoo tshaj IN.

Dhau li ntawd, qhov twg muaj vs sab hauv koom nrog kev ua tau zoo?

2 Teb. Feem ntau hais lus, SIJ HAWM thiab EXISTS yog yam txawv. Yog koj ua ib sab hauv koom ntawm UNIQUE kem, lawv nthuav tawm tib yam kev ua tau zoo . Yog koj ua ib sab hauv koom ntawm daim ntawv teev npe nrog DISTINCT thov (kom tshem tawm cov duplicates), EXISTS feem ntau yog sai dua.

Qhov thib ob, yog LEFT JOIN sai dua li koom? A LEFT JOIN tsis yog kiag li sai dua ib INNER Koom . Qhov tseeb, nws qeeb dua; los ntawm txhais, ib sab koom ( LEFT JOIN los yog TSIS MUAJ Koom ) yuav tsum ua txhua yam haujlwm ntawm INNER Koom ntxiv rau kev ua haujlwm ntxiv ntawm null-extending cov txiaj ntsig.

Nyob rau hauv no txoj kev, uas yog sai dua tshwm sim los yog nyob rau hauv?

Cov EXISTS clause ntau sai dua tshaj IN thaum cov txiaj ntsig subquery loj heev. Hloov pauv, IN clause yog sai dua tshaj EXISTS thaum cov txiaj ntsig subquery tsawg heev. Tsis tas li ntawd, IN clause tsis tuaj yeem sib piv ib yam dab tsi nrog NULL qhov tseem ceeb, tab sis cov EXISTS clause tuaj yeem sib piv txhua yam nrog NULLs.

Qhov twg SQL JOIN tau nrawm dua?

Zoo, feem ntau SIJ HAWM yuav yog sai dua vim nws tsuas yog xa rov qab cov kab sib tw hauv txhua lub rooj sib koom ua ke raws li kab sib koom. Tab sis LEFT Koom yuav rov qab tag nrho cov kab los ntawm cov lus teev tseg LEFT thiab tag nrho cov kab sib txuam los ntawm lub rooj teev tseg RIGHT.

Pom zoo: