V
V
Vladimir Golub2015-05-07 07:54:56
MySQL
Vladimir Golub, 2015-05-07 07:54:56

Where is the best place to place a query with the output of the nth number of rows?

There is such a request that displays information about the orders of a certain manager, as well as files attached to this order.

SELECT orders_design.id_order_design, clients.name, orders_design.id_order_print, orders_design.type_product, 

orders_design.parameters, orders_design.date_order FROM orders_design INNER JOIN clients ON orders_design.id_client = 

clients.id_client WHERE clients.id_manager = '1' AND files.name IN ( SELECT name FROM files WHERE id_order_design = 

orders_design.id_order_design)

The question is whether to leave a subrequest with the issuance of files or already make a separate request?
That is, roughly speaking, already in the code, take the order id and, depending on it, display files, there are simply orders without files, while I understood the request with a sub-request will not produce anything.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2015-05-07
@RazerVG

Your request still does not display file names.

SELECT `od`.`id_order_design`, `c`.`name`, `od`.`id_order_print`, 
        `od`.`type_product`, `od`.`parameters`, `od`.`date_order`, 
        `f`.`filelist`
    FROM `orders_design` AS `od`
    JOIN `clients` AS `c` ON `od`.`id_client` = `c`.`id_client`
    LEFT JOIN (
        SELECT `id_order_design`, GROUP_CONCAT(`name` SEPARATOR '|') AS `filelist`
            FROM `files`
            GROUP BY `id_order_design`
    ) AS `f` ON `f`.`id_order_design` = `od`.`id_order_design`
    WHERE `c`.`id_manager` = 1

A
Andrey Mokhov, 2015-05-07
@mokhovcom

something is not a request, but some kind of heresy, you know that it will not be executed?
I think while you debug the request, then the solution will come by itself ... separate the flies from the cutlets

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question