Public feed #888184

Untitled

public sql v1 · immutable
Raw Edit
·published 2008-02-01 22:45 UTC
rendered paste body
                SELECT                    *,                    (                        select order_id from order_lines ol2 where ol2.assoc_line_id = ol.line_id and ol.order_flag = 'EXTENDED' limit 1                    ) as extension,                    (                        select order_id from order_lines ol2 where ol2.assoc_line_id = ol.line_id and ol.order_flag = 'PURCHASED' limit 1                    ) as purchase,                    (                        select rl.label_key from return_labels rl left join return_label_lines rll on rl.id = rll.label_id where rll.line_id = ol.line_id order by rl.id desc limit 1                    ) as return_label,                    coalesce(ol.due_date, br.soft_return) as due_date                FROM                    `order_lines` ol                     left join book_returns br                    on br.line_id = ol.line_id                    left join bibliographic b                    on b.isbn = ol.book_isbn                WHERE                    ((:order_id = 0) OR `order_id` = :order_id)                    AND                    ((:status = 'ANY') OR `status` = :status)                    AND                    ((:line_id = 0) OR ol.`line_id` = :line_id)                    AND                    ((:shipment_id = 0) OR `shipment_id` = :shipment_id)                ORDER BY                    status ASC