Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL - Check if field contains string

SQL - Check if field contains string

Scheduled Pinned Locked Moved Database
databasemysqltoolstutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zanathel
    wrote on last edited by
    #1

    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'

    T 1 Reply Last reply
    0
    • Z Zanathel

      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'

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      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]

      Z 1 Reply Last reply
      0
      • T toxcct

        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]

        Z Offline
        Z Offline
        Zanathel
        wrote on last edited by
        #3

        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.

        T 1 Reply Last reply
        0
        • Z Zanathel

          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.

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          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]

          L 1 Reply Last reply
          0
          • T toxcct

            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]

            L Offline
            L Offline
            Leather99
            wrote on last edited by
            #5

            You may also want to consider the IN Syntax if you have the full id: SELECT * FROM MyTable WHERE MyField IN('Value1','Value2','Value3')

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups