FIND_IN_SET() alternative?

前端 未结 3 637
执念已碎
执念已碎 2021-01-15 02:33

I have a query that currently looks like:

SELECT [column a], [column b], [column c], [column d]
FROM [table] 
WHERE FIND_IN_SET(2, column d)
ORDER BY [colu         


        
3条回答
  •  既然无缘
    2021-01-15 03:26

    1- fulltext index is not a good idea in this case because: length of the string you searching for is small (1) in this case, and this won't be found (It is configurable though, but not a good idea)

    2- If this query is frequent, I suggest changing the tables' structure as follows:

    • table1 (col_a PK, col_b, col_c)
    • table2 (col_a FK, value_of_sub_d) where value_of_sub_d is one of (2, 3, ...)

    In this one-to-many relationship, you can either do a join, or get the PK from table2 where condition is met, and select that ID's row from table1 Example:

    Select * from table1 t1 inner join table2 t2 on t1.col_a=t2.col_a WHERE t2.value_of_sub_d=2
    

提交回复
热议问题