How to search records from database?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • waqasahmed996
    New Member
    • Jun 2008
    • 160

    How to search records from database?

    Hi
    I want to specify a search criteria but not know is it possible or not. My table has following fields and data.
    Code:
    Table name :  tablename
    fields     :  category        languageid         Data
    Data            1                 IS              Yes
                    1                 EN               *
                    2                 IS              Yes 
                    2                 EN              NULL
                    3                 IS              Yes
                    4                 IS              Yes
                    4                 EN              Yes
    Now what i want:

    I want to write a query which give me result for records where
    data against languageid 'IS' exist and data against languageid 'EN' is * or NULL or not exist.

    Please let me know if i am not clear in my question. I will be very thankful if you even just think to solve it.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    What are the results you're looking for?

    Comment

    • waqasahmed996
      New Member
      • Jun 2008
      • 160

      #3
      Thanks for reply
      i want to looking for first 5 records(upto category 3)

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        You can use a subquery to return the set of IDs you don't want and use that to filter them out.

        Comment

        • waqasahmed996
          New Member
          • Jun 2008
          • 160

          #5
          i found the solution. Thanks a lot for your cooperation. query can be
          Code:
          SELECT * FROM `aatest` where `languageid`='IS' and data!='' and `categoryid` not in (Select categoryid from aatest where languageid='EN' and data is not NULL and data!='*') or (`languageid`='EN' and (`data` ='*' or data is NULL))

          Comment

          Working...