Answer the question
In order to leave comments, you need to log in
Select from MySQL table by same field values. How is it better?
There is a table of students:
id|name|addr|langs|times|ages
1|Ivan|Kiev;Moscow|rus;ukr|Mon;Fri|4
2|Peter|Kharkov;Moscow|rus|Fri|4
3|Oleg|Riga |rus;lit|mon;tue|5
.......
etc.
From this data, you need to assemble a group - i.e. choose from the database of students with:
1. One city (example: Moscow - Ivan and Peter are suitable)
2. One language (example: Russian - all are suitable)
3. One day of the week (similarly)
4. One age.
One moment: If there is a "selection" in Moscow, for example, then those who have the city of Moscow + can "have" other cities. Also for other fields
. What is the best way to proceed here? And then only idiotic decisions come to mind
Answer the question
In order to leave comments, you need to log in
In this form, not really. First, normalize the table, put the cities and languages into related tables, convert the days of the week from a text string to the SET data type. Then the search will be simple and clear.
Fully agree with Rsa97. But if you can not change the structure of the database and normalize it, then look for the occurrence of a substring in a string:
1)
select * from table where instr ( concat(';',addr,';'),';Москва;') > 0
select * from table where instr ( concat(';',lang,';'),';рус;') > 0
select * from table where instr ( concat(';',times,';'),';пт;') > 0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question