T
T
Tiradoir2011-01-16 15:13:46
MySQL
Tiradoir, 2011-01-16 15:13:46

Applying correlated nested subqueries

There was a question on sql
The essence is as follows:

there are three tables , the

first, for example, with the fields “persons-titles-cities (code)”, the second “cities (code)-cities (decryption)-country (code)”, the third - “country ( code) -country (decryption) - continent.

At the input we have a variable, the value of which determines the person. What is the query to the database to get all the information from the three tables related to the person, that is, "title-city (decoding)-country (decoding)-continent"

The variant with the use of correlated nested subqueries is of particular interest.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexander Keith, 2011-01-16
@Tiradoir

I also wondered why correlated nested subqueries are of interest? It seems to me in this case it is not appropriate, or?
Just in case, inner join:

select person.Description, city.cityName, state.Name from person
  inner join city on city.cityId = person.cityId
  inner join state on state.stateId = city.stateId
  
where preson.id = @personId

S
Sannis, 2011-01-16
@Sannis

Some too simple question. Try to solve puzzles on sql-ex.ru/ to gain experience :)

A
antonick, 2011-01-16
@antonic

But this didn't work for you?

T
Tiradoir, 2011-01-16
@Tiradoir

The solution sent to me on twitter, which I use:
SELECT 1.title, 2.city, 3.country, 3.continent FROM 1, 2, 3 WHERE 1.person = "Spock" AND 1.k_city = 2.k_city AND 2.to_country = 3.to_country

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question