Select Subqueries

0

My bank looks like this:

cd_cliente |  nr_ddd  |   nr_telefone
30         |  11      |   25622791
30         |  11      |   25622791

My select is like this:

"SELECT * FROM tb_telefones WHERE nr_ddd="+ddd+" AND nr_telefone="+telefone+"";

It returns from the database from the ddd and phone parameters, the numbers that are equal to them.

I want that from this parameters (nr_ddd and nr_telefone), it returns the value of cd_client, and make a new query, returned tos ddds and phones that have cd_client equal.

    
asked by anonymous 25.11.2014 / 14:12

1 answer

3

Given that the table "tb_telefones" has the columns you mentioned (which makes sense), then this select might help you:

SELECT * FROM tb_telefones 
WHERE cd_cliente IN (SELECT cd_cliente FROM tb_telefones 
                     WHERE nr_ddd="+ddd+" 
                     AND nr_telefone="+telefone+")

Ensure that ddd and nr_telefone are integer and will not have problems with select.

    
25.11.2014 / 14:58