MYSQL - How to Filter the Output of a main Select that has as one of the fields the result of a subquery?

Asked

Viewed 32 times

0

Good afternoon Srs, this is my first post here, but I’m always researching the posts and the doubts of the people.
I have the following situation:
I CAN get all results, but I cannot FILTER what I want using as parameter the field of select that is the result of a subquery.
He even highlighted what I want but he brings all the records ,what I set to filter and what does not answer he returns me the line with the field in WHITE, in the part of the code that deals SELLER.
Below I put two prints of the code executed with the 'param2' filled with IOLANDA.
What is outside???

SELECT
    SA1_DESC  AS 'CLIENTE PRINCIPAL',
    CASE
        WHEN SAR_IDSA1REL1 > 0
            THEN (SELECT SA1_DESC FROM SA1 WHERE SA1_ID = SAR_IDSA1REL2 AND 
        SAR_RELACIONAMENTO <> ' ')

    END AS 'RELACIONADOS',
    SAR_Relacionamento AS 'RELACIONAMENTO',
    SA1_CONTATO AS 'RESPONSÁVEL',
    SA1_EMail AS 'E-MAIL',
    SA1_TelCom AS 'TEL COM',
    SA1_TelRes AS 'TEL RES',
    SA1_TelCel AS 'TEL CELULAR',

    (SELECT SA3_DESC FROM SA3 
    WHERE SA3_ID =  SA1_SA3_IDSA3 AND SA3_DESC LIKE '%$param2%') as 'VENDEDOR'

FROM SA1
INNER JOIN EA1 ON EA1_ID = SA1_IDEA1
LEFT JOIN SAR ON SAR_IDSA1REL1 = SA1_ID
LEFT JOIN SA3 ON SA3_ID = SA1_IDSA3
INNER JOIN SA1_SA3 ON SA1_SA3_IDSA1 = SA1_ID

WHERE SA1_DESC LIKE '%$param1%'

exemplo sem preenchimento

exemplo com param2 preenchido

  • I corrected the search for what appear to be the relations between the tables - although not functional.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.