SQL - Check if field contains string
-
Hi, I'm currently developing a forge where all the receipts is stored in a mySQL database. The players suppose to insert their items within the forge, and activate it. When the forge activates, the script goes through each item located within, and get the unique id for each item. An example of a result would be: item1 item4 items5 item8 I want to check if the field 'components' contains these id's. If so, the row should be returned. I've tried the following statement, but will it work if the order were differnt? SELECT FROM `recept` WHERE `komponenter` LIKE 'item1%item4%item5%item8'
-
Hi, I'm currently developing a forge where all the receipts is stored in a mySQL database. The players suppose to insert their items within the forge, and activate it. When the forge activates, the script goes through each item located within, and get the unique id for each item. An example of a result would be: item1 item4 items5 item8 I want to check if the field 'components' contains these id's. If so, the row should be returned. I've tried the following statement, but will it work if the order were differnt? SELECT FROM `recept` WHERE `komponenter` LIKE 'item1%item4%item5%item8'
-
it will work... notice that a select don't know the order of the records in a table... if you want to sort the, use after your where statement the
ORDER BY
keywords...
TOXCCT >>> GEII power
[toxcct][VisualCalc]Thank you for your reply! So if komponenter contains the ID's arranged in the following order: item1 item5 item3 item2 item4 ... a SQL statement like this will find the row?
SELECT `...` FROM `recept` WHERE `komponenter` LIKE '%item5%item4%item3%item2%item1%'?
The reason I'm asking instead of just trying, is the fact that each time I want to try something out, I have to update the server via a console-interface - after I've uploaded the 25 meg new version of the game. -
Thank you for your reply! So if komponenter contains the ID's arranged in the following order: item1 item5 item3 item2 item4 ... a SQL statement like this will find the row?
SELECT `...` FROM `recept` WHERE `komponenter` LIKE '%item5%item4%item3%item2%item1%'?
The reason I'm asking instead of just trying, is the fact that each time I want to try something out, I have to update the server via a console-interface - after I've uploaded the 25 meg new version of the game.nop, you don't have it.
SELECT komponenter
FROM recept
WHERE komponenter LIKE 'item%'
ORDER BY komponenter ASC;this will return :
item1 item2 item3 item4 item5
well, tell me, i don't know what database you're using in your SW, but you might have tool to test SQL statements before updating your whole code and test it each time you change your query... (Entreprise Manager
with SQL Server 2000,SQL*Plus
with Oracle DB...)
TOXCCT >>> GEII power
[toxcct][VisualCalc] -
nop, you don't have it.
SELECT komponenter
FROM recept
WHERE komponenter LIKE 'item%'
ORDER BY komponenter ASC;this will return :
item1 item2 item3 item4 item5
well, tell me, i don't know what database you're using in your SW, but you might have tool to test SQL statements before updating your whole code and test it each time you change your query... (Entreprise Manager
with SQL Server 2000,SQL*Plus
with Oracle DB...)
TOXCCT >>> GEII power
[toxcct][VisualCalc]