sql - Is this possible using inner joins in MySQL? -
sql - Is this possible using inner joins in MySQL? -
i'm stuck on trying build query include given order_reference cover file info sample below if of print_item_qty values of files under same order_reference equal 5.
is possible using joins or outside remit of single query?
i've tried building inner joins cannot work out how restrict results cover row when component parts of order have equal values in print_item_qty column.
here base of operations select query , sample data:
select c1.`order_id`,c1.name1,c1.name2,c1.`print_item_qty`,c1.`sub_item_type`, c1.`order_reference` print_items; +--------------+-------+---------+----------------+---------------+-----------------+ | order_id | name1 | name2 | print_item_qty | sub_item_type | order_reference | +--------------+-------+---------+----------------+---------------+-----------------+ | 000003201875 | jason | bramley | 5 | cover | 1875 | | 000003201875 | jason | bramley | 5 | inner | 1875 | | 000003201875 | jason | bramley | 1 | card | 1875 | | 000003201876 | jason | bramley | 5 | cover | 1876 | | 000003201876 | jason | bramley | 5 | inner | 1876 | +--------------+-------+---------+----------------+---------------+-----------------+
my desired result above sample info next row:
+--------------+-------+---------+----------------+---------------+-----------------+ | order_id | name1 | name2 | print_item_qty | sub_item_type | order_reference | +--------------+-------+---------+----------------+---------------+-----------------+ | 000003201876 | jason | bramley | 5 | cover | 1876 | +--------------+-------+---------+----------------+---------------+-----------------+
any help give point me in right direction appreciated.
many thanks.
so want verify select info orders print_item_qty = 5 sub_item_type in order_reference.
to this, utilize subsquery
select order_reference, max(print_item_qty), min(print_item_qty) print_items grouping order_reference having max(print_item_qty) = 5 , min(print_item_qty) = 5
and bring together original dataset. subquery restrict ids want, , joining homecoming rows associated order_references print_item_qty = 5 every sub_item_type, eg,
select c1.`order_id`, c1.name1, c1.name2, c1.`print_item_qty`, c1.`sub_item_type`, c1.`order_reference` print_items c1 inner bring together (select order_reference, max(print_item_qty), min(print_item_qty) print_items grouping order_reference having max(print_item_qty) = 5 , min(print_item_qty) = 5) b on c1.order_reference = b.order_reference
mysql sql join
Comments
Post a Comment