Answer the question
In order to leave comments, you need to log in
How to pull a record in a nested SELECT using the current code of the outer SELECT?
There are such tables, I will not describe all the fields, the main connection:
Main, everything is just here - your code + 2 links to the classifier tables.
------------------------------
| m_plan |
------------------------------------
| CODE(int) |
| NAME_WORK(VARCHAR[255]) |
| DATE(timestamp) |
--------------------
Link table - does it contain the code from the m_plan table? as well as the relationship with the table m_clients
----------------------
| mc_customer |
----------------------
| PLAN_CODE(int) |
| CLIENT_CODE(int)|
----------------------
Table of clients, it's just a code and a name
------------------------------
| m_clients |
------------------------------
| CODE(int) |
| NAME(VARCHAR[255])|
------------------------------
There is such a query:
SELECT
(
SELECT
m_clients.NAME
FROM
m_clients
LEFT JOIN
mc_customer
ON
mc_customer.CLIENT_CODE = m_clients.CODE
LEFT JOIN
m_plan
ON
mc_customer.PLAN_CODE = m_plan.CODE
WHERE
mc_customer.PLAN_CODE = 'x') ,
m_plan.CODE,
m_plan.NAME_WORK,
FROM m_zakaz I'm
interested in the fat part of the query, I need to get the given customer name as one record, not as an array , then, (WHERE mc_customer.PLAN_CODE = 'x') I would like to omit or turn into something - like:
WHERE
mc_customer.PLAN_CODE = CURRENT(m_plan.CODE)
THAT is, you need the current code of the iteration plan, is it possible at all in Mysql without using C ++, such a task is necessary for the normal operation of the grid in the Devexpress Library for VCL
Answer the question
In order to leave comments, you need to log in
Let's start with the fat one. It selects all records from m_clients regardless of the condition mc_customer.PLAN_CODE = 'x'. For this condition to work, both LEFT JOINs must be replaced with JOINs.
Now let's look at the relationship between entities. The scheme that you described implies that there is a Many-To-Many relationship between m_plan and m_clients, which is described in mc_customer. In this case, the bold query will always return an array. If in fact the plan can only have one client (or vice versa), then you need to change the scheme.
Well, about the request itself - did not understand what exactly you want to receive? The CURRENT() function does not exist in MySQL (or indeed in SQL).
PS Please use the built-in editor to design the code.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question