Simple Sub Query Sql

Kadang kita perlu mencari dan membandingkan data dari 2 table ytang berbeda tanpa melakukan JOIN ke table lain.

Berikut cara sederhana yang dapat digunakan.

SELECT stockid,
loccode,
sum(quantity) as hasil,
(select sum(qty) FROM T2 where T2.stockid=T1.stockid and T2.loccode='” . $_POST[‘Location’] . “‘) as total
FROM T1
where loccode='” . $_POST[‘Location’] . “‘
GROUP by stockid

disini saya mencontohkan dari table T1 dan T2 untuk melihat total quantity dari masing-masing table dengan stockid untuk menentukan kode barang yang sama dan loccode dari lokasi gudang

Exit mobile version

Notice: ob_end_flush(): Failed to send buffer of zlib output compression (1) in /home/esujiant/public_html/wp-includes/functions.php on line 5427

Notice: ob_end_flush(): Failed to send buffer of zlib output compression (1) in /home/esujiant/public_html/wp-includes/functions.php on line 5427

Notice: ob_end_flush(): Failed to send buffer of zlib output compression (1) in /home/esujiant/public_html/wp-content/plugins/really-simple-ssl/class-mixed-content-fixer.php on line 107