how to query to database in order get pending po list.
I have four table purchase_order
with this fields
`po_id` // primary key
`supplier_id`
'date`
`status`
'description`
`po_detail` with this fields
`pod_id` // primary key
`po_id`
`product_id`
`rate`
`qty`
`grn` with this fields
`grn_id` // primary key
`date`
`description`
`supplier_id`
`grn_detail` with this fields
`grnd_id` // primary key
`grn_id`
`rate`
`qty`
`product_id`
`po_id`
now i am to select all product from po_detail which is not entered in grn_detail
with that po_id
OR entered into grn_detail
but grn_detail.qty
is < po_detail.qty
with same po_id could you please write the query. if possile please write with demo in sqlfiddle
please have look in SQLFIDDLE
first answer is quite well but i think there may little changes in operator. something like that >=
SELECT * FROM `po_detail`
WHERE
`po_detail`.`po_id` NOT IN
(SELECT `grn_detail`.`po_id` FROM `grn_detail`
WHERE (`grn_detail`.`po_id` <> `po_detail`.`po_id`) OR
(`grn_detail`.`qty` >= `po_detail`.`qty`))
AND your_other_filter_if_you_want_to
Try this:
SELECT * FROM `po_detail`
WHERE
`po_detail`.`po_id` NOT IN
(SELECT `grn_detail`.`po_id` FROM `grn_detail`
WHERE (`grn_detail`.`po_id` <> `po_detail`.`po_id`) OR
(`grn_detail`.`qty` > `po_detail`.`qty`))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.