What is better subquery vs literal on IN clause in mysql

It all depends on your initial requirements. If you know the values (here 1,2,3,4) are static, you may hard code them. But if they will change in the future, it is better to use the sub query. Normally subquery is more durable but more resource consuming.

Please elaborate on your requirements, so that we can understand the problem and answer you better.

EDIT 1:

Ok, first of all, i have never seen a EAV model on two table, basically it is done with one table. In you case you will have difficulty searching for the key in the two table when you can combine them in one table. Ideally, you table should be like this :

CREATE TABLE BOARD
(
   BoardKey INT UNSIGNED,
   Content TEXT,
   Value TEXT
   PRIMARY KEY (BoardKey)
)

Finally, you can do

SELECT * FROM BOARD WHERE Value="SOME"

If the value ‘SOME’ will change in the future, better stick with Subquery. Hope it helped, vote answered if so.

Leave a Comment