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. query problem

query problem

Scheduled Pinned Locked Moved Database
databasehelp
8 Posts 4 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.
  • D Offline
    D Offline
    Dhyanga
    wrote on last edited by
    #1

    hi I am trying to run this query

    select Name from data where id='67' and file like '[pdfrtfdoc]%'

    and it didn't give any data. well if my query is either

    select Name from data where file like '[pdfrtfdoc]%'

    or

    select Name from data where id='67'

    it runs. and also in the database it has record having id = 67 and file = *.pdf file. Need quick help.

    suchita

    C L W 3 Replies Last reply
    0
    • D Dhyanga

      hi I am trying to run this query

      select Name from data where id='67' and file like '[pdfrtfdoc]%'

      and it didn't give any data. well if my query is either

      select Name from data where file like '[pdfrtfdoc]%'

      or

      select Name from data where id='67'

      it runs. and also in the database it has record having id = 67 and file = *.pdf file. Need quick help.

      suchita

      C Offline
      C Offline
      Chris Meech
      wrote on last edited by
      #2

      Try this

      where file in ('%pdf', '%rtf', '%doc')

      :)

      Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

      D 1 Reply Last reply
      0
      • C Chris Meech

        Try this

        where file in ('%pdf', '%rtf', '%doc')

        :)

        Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

        D Offline
        D Offline
        Dhyanga
        wrote on last edited by
        #3

        Sorry that wasn't my question. I have two conditions one is id check and another is file check. If i put one of those conditions, it runs but if i put two conditions , then its not running.

        suchita

        C 1 Reply Last reply
        0
        • D Dhyanga

          Sorry that wasn't my question. I have two conditions one is id check and another is file check. If i put one of those conditions, it runs but if i put two conditions , then its not running.

          suchita

          C Offline
          C Offline
          Chris Meech
          wrote on last edited by
          #4

          If by "not running" you mean that no rows are returned, then that means that the rows returned from running the id check are different than the rows returned from running with the file check. :)

          Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

          1 Reply Last reply
          0
          • D Dhyanga

            hi I am trying to run this query

            select Name from data where id='67' and file like '[pdfrtfdoc]%'

            and it didn't give any data. well if my query is either

            select Name from data where file like '[pdfrtfdoc]%'

            or

            select Name from data where id='67'

            it runs. and also in the database it has record having id = 67 and file = *.pdf file. Need quick help.

            suchita

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            why is 67 in quotes? ID fields normally are numeric, for maximum performance, and numeric literals don't take quotes. :)

            Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

            D 1 Reply Last reply
            0
            • L Luc Pattyn

              why is 67 in quotes? ID fields normally are numeric, for maximum performance, and numeric literals don't take quotes. :)

              Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

              D Offline
              D Offline
              Dhyanga
              wrote on last edited by
              #6

              no i tried both. actually is it possible to have sql conditions where there is LIKE condtion and other normal condition in the same statement. I can't find that example either. something like

              select Name from data where id=67 and file like '[pdfrtfdoc]%'

              or

              select Name from Grapp1L where Name='suchita' and file like '[pdfrtfdoc]%'

              the above both statements didn't run though i have data in both fields on the same row. when i run with only one condition, it runs. I have never tried LIKE condition with any other conditions. well I am familiar with multiple conditions though.

              suchita

              L 1 Reply Last reply
              0
              • D Dhyanga

                hi I am trying to run this query

                select Name from data where id='67' and file like '[pdfrtfdoc]%'

                and it didn't give any data. well if my query is either

                select Name from data where file like '[pdfrtfdoc]%'

                or

                select Name from data where id='67'

                it runs. and also in the database it has record having id = 67 and file = *.pdf file. Need quick help.

                suchita

                W Offline
                W Offline
                Wendelius
                wrote on last edited by
                #7

                Since you have AND between the conditions both conditions must be true on the same row. So if you don't get any results with those two conditions but you do get results when using the conditions separately, you don't have a row in the table that satisfies both conditions at the same time. Also when you use LIKE operator like that, you select all rows that start with letters P, D, F, R, T, F (again), D(again), O or C. For example if the field file contains a value 'test.abc', this will satisfy the condition since it start with the letter T. Is this what you really want?

                The need to optimize rises from a bad design.My articles[^]

                1 Reply Last reply
                0
                • D Dhyanga

                  no i tried both. actually is it possible to have sql conditions where there is LIKE condtion and other normal condition in the same statement. I can't find that example either. something like

                  select Name from data where id=67 and file like '[pdfrtfdoc]%'

                  or

                  select Name from Grapp1L where Name='suchita' and file like '[pdfrtfdoc]%'

                  the above both statements didn't run though i have data in both fields on the same row. when i run with only one condition, it runs. I have never tried LIKE condition with any other conditions. well I am familiar with multiple conditions though.

                  suchita

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  SayamiSuchi wrote:

                  no i tried both

                  only string literals need quotes. numeric literals don't.

                  SayamiSuchi wrote:

                  is it possible to ...

                  yes, of course. add a record that has id=67 and file="pqr", then try

                  select Name from data where id=67 and file like 'p%'

                  :)

                  Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                  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