Subselect within a field

-1

I'm displaying multiple fields through a SELECT:

SELECT razaosocial, nomefantasia, cnpj, ie, im, endereco, endereco_numero, endereco_complemento, codCedente FROM cliente WHERE razaosocial LIKE '%carvalho%' .

So far, all right. But there I also display the codeCenter, which comes numeric, how can I make a SELECT there within the code to search for the reasonableness within a table called ASSIGNMENT? (select from the source where the codenumber = 'codenumber') the codenumber .. let's say this way?

    
asked by anonymous 14.10.2015 / 17:37

1 answer

1

Explanation

I think the easiest (I think more performative) way of doing this would be to use JOIN with the Assignor table.

Query

SELECT 
    c.razaosocial, 
    c.nomefantasia, 
    c.cnpj, 
    c.ie, 
    c.im, 
    c.endereco, 
    c.endereco_numero, 
    c.endereco_complemento, 
    ce.razaosocial
FROM 
    cliente c 
    INNER JOIN cedente ce on ce.codCedente = c.codCedente
WHERE 
    razaosocial LIKE '%carvalho%'
    
14.10.2015 / 18:14