There are two tables. the first one stores a list of something, and there is a special column for categories that are written there in the form of numbers. In the second table "decryption" categories. Those. each digit corresponds to a word.
With the help of JOIN'a you can make so that on the page there was one table in which instead of a digit in the category column there was a word corresponding to a digit.
But how to do the same, if the first table in the category column is not a single digit?
Example:
Table 1

+---------+----+ |bla-bla | 3| +---------+----+ |bla-bla | 1 2| +---------+----+ 

table 2

 +--+---------+ | 1|type-1 | +--+---------+ | 2|type-2 | +--+---------+ | 3|type-3 | +--+---------+ 

The result should be this:

 +---------+-------------+ |bla-bla |type-3 | +---------+-------------+ |bla-bla |type-1 type-2| +---------+-------------+ 

    3 answers 3

    This problem is solved as follows: tables {fields}:

     category {id, name} product {id, name} product_categories {product_id, category_id} 

    request:

     select p.name, c.name from category c, product p, product_categories pc where p.id = pc.product_id and c.id = pc.category_id order by p.name /* можно по c.id - как вам удобнее */ 

    ps it makes sense to read about relational databases and normal forms.

      As far as I know, SQL does not provide such capabilities to return multivariate fields. Try to revise the tables, normalize them so that there are separate fields with codes.

      • If so, then very sad ... - oleg_ismaylov

      I know a cloud of places where people work this way - there is a certain field where the numeral is full (or as a variant of characters) - depending on the position of the numbers (well, like a bit field), something means. For example, if the character in the 17th position is "1" the entry is considered marked for deletion :)

      And they use such good companies, not PE "Pupkin", but of those advertisements which are filled with all our streets and on TV they are hammered once a day.

      At first, I was trying to outrack, telling people to be good-eternal talked about the theorem of Beuys-Codd, and so on. nonsense - then I realized that this is life. And this is also industry-standard, or as the vendor-specific legacy system sometimes says.

      • 2
        We will wait for SQL extensions to work with such "vectors". They didn’t try to reduce life to the relational model, but nature takes its toll. - avp
      • already there, for example. nested tables at oracle - jmu
      • Yes, in TecDoc this is also done - they are looking for a certain position in the field and compare it with the value - Ale_x
      • Nope, web developers will be leaving SQL soon because it’s hard for them. And in fact, they have never been a serious audience. - karmadro4
      • Well, a web developer without any knowledge of SQL - is this probably PHP file? Most Java frameworks work on similar frameworks with JPA, and you’ll never miss it - Barmaley