Answer the question
In order to leave comments, you need to log in
How to organize a selection in SQL?
Good evening.
I am currently working with the FIAS database.
When registering, a person enters his city and a list with matches is loaded from the database.
All data is combined in one table.
Everything is built in a hierarchical system - the city has a parentguid which points to the aoguid of the region, region, etc.
I decided to combine all the necessary data into one View in MySQL.
VIEW `ADDR_TEST` AS select `a`.`id` AS `id`,`a`.`AOGUID` AS `AOGUID`,
`a`.`AOLEVEL` AS `AOLEVEL`,concat(`a`.`SHORTNAME`,',',`a`.`FORMALNAME`,' ( ',`b`.`FORMALNAME`,' ',`b`.`SHORTNAME`,' )') AS `NAME`
from (`addr_table` `a` join `addr_table` `b`)
where ((`a`.`AOLEVEL` in (4,6)) and (`b`.`AOLEVEL` = '3') and (`a`.`PARENTGUID` = `b`.`AOGUID`) and (`a`.`LIVESTATUS` = 1) and (`b`.`LIVESTATUS` = 1) and (`a`.`ACTSTATUS` = 1) and (`b`.`ACTSTATUS` = 1) and (`a`.`CURRSTATUS` = 0) and (`b`.`CURRSTATUS` = 0))
order by `a`.`AOLEVEL`
concat(`a`.`SHORTNAME`,',',`a`.`FORMALNAME`,' ( ',`b`.`FORMALNAME`,' ',`b`.`SHORTNAME`,' )') AS `NAME`
(`a`.`PARENTGUID` = `b`.`AOGUID`)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question