There is a table ' country ' with a list of countries

 cid | title 

and a places table with a list of excursions in the countries

 pid | country | title 

where ' places.country ' = ' country.cid '.


The question is as follows. How to display in one query all the title from ' country ', which are mentioned in the ' places ' table? I do not want to divide it into several requests.

    1 answer 1

    SELECT DISTINCT c.title FROM country c JOIN places p ON p.country = c.cid;

    • OK. But what about such a request, where the contents of the p.country match c.cid , but at the same time p.country can be equal to a chain separated by several dashes, for example, -14-15-16- ? Something like% -p.country-% LIKE c.cid - NoName
    • @NoName - It seems to me that you need to read about database normalization. - Opalosolo
    • @ ua6xh, thanks, I already found the answer. - NoName