JOIN એક condition, સામાન્ય રીતે foreign key, ને match કરીને બે tables ની rows જોડે છે. join નો type નક્કી કરે છે કે બીજી બાજુ કોઈ match ન હોય તેવી rows સાથે શું થાય.
JOIN એક condition, સામાન્ય રીતે foreign key, ને match કરીને બે tables ની rows જોડે છે. join નો type નક્કી કરે છે કે બીજી બાજુ કોઈ match ન હોય તેવી rows સાથે શું થાય.
NULL તરીકે પાછા આવે છે.-- customers(id, name) orders(id, customer_id, total)
-- INNER: only customers who have at least one order
SELECT c.name, o.total
FROM customers c
INNER JOIN orders o ON o.customer_id = c.id;
-- LEFT: every customer, even those with zero orders (total = NULL)
SELECT c.name, o.total
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id;
-- Classic use: find customers with NO orders
SELECT c.name
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
WHERE o.id IS NULL; -- the LEFT JOIN's NULL side reveals the gap
WHERE માં right table ને filter કરવું (દા.ત. WHERE o.total > 100) ચૂપચાપ LEFT JOIN ને પાછું INNER JOIN માં ફેરવી નાખે છે, કારણ કે NULL > 100 એ false છે. જો તમે match ન થયેલી rows રાખવા માંગતા હો તો આવી conditions ON clause માં મૂકો.મોટા ભાગની વાસ્તવિક queries એકથી વધુ tables ને આવરી લે છે, અને ખોટો join type ચૂપચાપ rows ને drop કરે છે કે duplicate કરે છે — એક એવો bug જે વિશ્વસનીય લાગતાં પરિણામો પાછાં આપે છે. LEFT JOIN + IS NULL "ગુમ" rows શોધે છે, અને null બાજુ પર WHERE LEFT ને રદ કરે છે એ જાણવાથી reporting ભૂલોનો આખો વર્ગ અટકે છે.
વિગતવાર જવાબો સાથે IT ઇન્ટરવ્યૂ પ્રશ્નોની લાઇબ્રેરી — જુનિયરથી સિનિયર સુધી.
દાન કરો