Retrieve data for multiple single or reference without like operator

前端 未结 2 1292
遥遥无期
遥遥无期 2021-01-22 11:30

I have two tables, which looks like below. In the employee table instead mentioning the skills directly, I\'m using as reference from another table.

Question

2条回答
  •  生来不讨喜
    2021-01-22 11:59

    As mentioned by others in the comments, this is not the most useful design choice as it would make it long winded to create a simple CRUD interface to interact with these values.

    You would have ideally:

    employee table:

    +-----+-------------+
    | id  | name        |
    +-----+-------------+
    | 1   | Bob         |
    | 2   | Mary        |
    +-----+-------------++
    

    skillset table:

    +-----+-------------+
    | id  | skillset    |
    +-----+-------------+
    | 1   | Python      |
    | 2   | Java        |
    | 3   | C           |
    | 4   | PHP         |
    +-----+-------------+
    

    employee_skillset table:

    +-----+---------------+---------------+
    | id  | employee_id   | skillset_id   |
    +-----+---------------+---------------+
    | 1   | 1             | 1             |
    | 2   | 1             | 2             |
    | 3   | 1             | 4             |
    | 4   | 2             | 1             |
    | 5   | 2             | 3             |
    +-----+---------------+---------------+
    

    Then you could do:

    SELECT *
    FROM employee e
    INNER JOIN employee_skillset es
    ON e.id = es.employee_id    
    WHERE es.skillset_id = "1";
    

    You could use the skillset table in the CRUD interface as selectable / editable options.

    EDIT:

    It's easy enough to include a range of skills within this too using the IN clause:

    WHERE es.skillset_id IN (1, 3, 4);
    

提交回复
热议问题