Subconsultas Select

Asked

Viewed 98 times

0

My bank is like this:

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

My select is so:

"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 these parameters (parameters nr_ddd and nr_phone), it returns the value of cd_client, and make a new query, returned to the ddds and phones that have cd_client equal.

  • 2

    Your question is confused. Re-read and adjust so we can help you. If possible inform the structure of the tables and be clearer about what you need.

1 answer

3


As long as the table "tb_telefones" has the columns you mentioned (which makes sense), then this select can 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 have no problems with select.

Browser other questions tagged

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