Selecting specific SQL Server values

Asked

Viewed 26 times

1

First thank you for your time!

I don’t know much about SQL, I have a question about how to perform a select.

I have some tables, follow these as an example: inserir a descrição da imagem aqui

How do I give a select to know the people who are registered, showing your city, but without duplicating the registration Gustavo visited two cities there but I want him to appear only once in the register. When I open his registration form, it will show the cities he visited, with this example I can accomplish what I want, someone can help me?

1 answer

1


The two of you together, I don’t think you can do it, but you can do it one at a time:

1- Search People with their Cities

select Pessoa.id, Pessoa.nome, Cidade.id, Cidade.nome, Cidade.UF from Pessoa inner join Cidade on Pessoa.cidade_id = Cidade.id

2- Then where you will show the cities that each person visited you makes:

select Cidade.id, Cidade.nome, Cidade.UF where Cidade.id in (select CidadesVisitadas.cidade_id where CidadesVisitadas.pessoa_id = 1)

Where I put "1", you would put some "Person.id" brought from the first select.

  • 1

    The yes is a possibility, obliged to judou mt

Browser other questions tagged

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