Mysql sql like

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tomek

    Mysql sql like

    What should I write after sql like for finding hole words
    and not for words in string sequence. I tryied "like space variable space"
    but it's not working for me. Database is MYSQL.


  • Aggro

    #2
    Re: Mysql sql like

    tomek wrote:
    [color=blue][color=green]
    >>Sorry, but I didn't understand the question. I give you a few examples,
    >>hopefully they help:
    >>
    >># Only names that contain Jack and only Jack are returned
    >>select * from tablename where name like 'Jack';[/color]
    >
    >
    > But when i wrote select with like 'oki' I haven't got returned result
    > though in database there are words oki for example in sentence
    > 'Teczki Oki rozdane'[/color]

    # If we have 6 rows and the column we search for has these values
    # 'Teczki Oki rozdane'
    # 'TeczkiOkirozda ne'
    # 'Oki rozdane'
    # 'Teczki Oki'
    # 'Oki'
    # 'Jack'

    # For exact match
    # columns like this would match:
    # 'Teczki Oki rozdane'
    select * from tablename where columnname like 'Teczki Oki rozdane';

    # To select all rows where columnname has Oki in the middle of it. i.e.
    # columns like this would match:
    # 'Teczki Oki rozdane'
    # 'TeczkiOkirozda ne'
    # 'Oki rozdane'
    # 'Teczki Oki'
    # 'Oki'
    select * from tablename where columnname like '%Oki%';

    # Same as abow, except there must be whitespace surrounding the word
    # i.e. columsn like this would match:
    # 'Teczki Oki rozdane'
    select * from tablename where columnname like '% Oki %';

    # This might get slow with large amounts of data, but it will return
    # 'Teczki Oki rozdane'
    # 'Oki rozdane'
    # 'Teczki Oki'
    # 'Oki'
    select * from tablename where name like '% Oki %' or name like 'Oki %'
    or name like '% Oki' or name like 'Oki';

    Comment

    • Aggro

      #3
      Re: Mysql sql like

      tomek wrote:
      [color=blue]
      > What should I write after sql like for finding hole words
      > and not for words in string sequence. I tryied "like space variable space"
      > but it's not working for me. Database is MYSQL.[/color]

      Sorry, but I didn't understand the question. I give you a few examples,
      hopefully they help:

      # Only names that contain Jack and only Jack are returned
      select * from tablename where name like 'Jack';

      # Only names that have Jack somewhere in it. i.e. 'I like Jack'
      # are returned.
      select * from tablename where name like '%Jack%';

      # Only names that match for Jack or Lisa are returned
      select * from jack where name like 'Jack' or name like 'Lisa';


      Comment

      • tomek

        #4
        Re: Mysql sql like

        > Sorry, but I didn't understand the question. I give you a few examples,[color=blue]
        > hopefully they help:
        >
        > # Only names that contain Jack and only Jack are returned
        > select * from tablename where name like 'Jack';[/color]

        But when i wrote select with like 'oki' I haven't got returned result
        though in database there are words oki for example in sentence
        'Teczki Oki rozdane'




        Comment

        • Aggro

          #5
          Re: Mysql sql like

          tomek wrote:
          [color=blue][color=green]
          >>Sorry, but I didn't understand the question. I give you a few examples,
          >>hopefully they help:
          >>
          >># Only names that contain Jack and only Jack are returned
          >>select * from tablename where name like 'Jack';[/color]
          >
          >
          > But when i wrote select with like 'oki' I haven't got returned result
          > though in database there are words oki for example in sentence
          > 'Teczki Oki rozdane'[/color]

          # If we have 6 rows and the column we search for has these values
          # 'Teczki Oki rozdane'
          # 'TeczkiOkirozda ne'
          # 'Oki rozdane'
          # 'Teczki Oki'
          # 'Oki'
          # 'Jack'

          # For exact match
          # columns like this would match:
          # 'Teczki Oki rozdane'
          select * from tablename where columnname like 'Teczki Oki rozdane';

          # To select all rows where columnname has Oki in the middle of it. i.e.
          # columns like this would match:
          # 'Teczki Oki rozdane'
          # 'TeczkiOkirozda ne'
          # 'Oki rozdane'
          # 'Teczki Oki'
          # 'Oki'
          select * from tablename where columnname like '%Oki%';

          # Same as abow, except there must be whitespace surrounding the word
          # i.e. columsn like this would match:
          # 'Teczki Oki rozdane'
          select * from tablename where columnname like '% Oki %';

          # This might get slow with large amounts of data, but it will return
          # 'Teczki Oki rozdane'
          # 'Oki rozdane'
          # 'Teczki Oki'
          # 'Oki'
          select * from tablename where name like '% Oki %' or name like 'Oki %'
          or name like '% Oki' or name like 'Oki';

          Comment

          • Andrew DeFaria

            #6
            Re: Mysql sql like

            tomek wrote:
            [color=blue][color=green]
            >> Sorry, but I didn't understand the question. I give you a few
            >> examples,hopefu lly they help:
            >>
            >> # Only names that contain Jack and only Jack are returned select *
            >> from tablename where name like 'Jack';[/color]
            >
            > But when i wrote select with like 'oki' I haven't got returned result
            > though in database there are words oki for example in sentence 'Teczki
            > Oki rozdane'[/color]

            Perhaps 'oki' <> 'Oki'.

            --
            Double your drive space - delete Windows!

            Comment

            • Andrew DeFaria

              #7
              Re: Mysql sql like

              tomek wrote:
              [color=blue][color=green]
              >> Sorry, but I didn't understand the question. I give you a few
              >> examples,hopefu lly they help:
              >>
              >> # Only names that contain Jack and only Jack are returned select *
              >> from tablename where name like 'Jack';[/color]
              >
              > But when i wrote select with like 'oki' I haven't got returned result
              > though in database there are words oki for example in sentence 'Teczki
              > Oki rozdane'[/color]

              Perhaps 'oki' <> 'Oki'.

              --
              Double your drive space - delete Windows!

              Comment

              Working...