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. How to select the row if one column having text field

How to select the row if one column having text field

Scheduled Pinned Locked Moved Database
databasetutorial
6 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.
  • S Offline
    S Offline
    sr159
    wrote on last edited by
    #1

    I have a column called bookedhalls, the value will be stored as Balaji-A,Balaji-C, i written select query as follows Select * from function where bookedhalls like '%Balaji-A,Balaji-C,% by using this i will get the row. Suppose if i give '%Balaji-C,Balaji-A,%' i cannot get the row. How to get that row by using Balaji-C,Balaji-A. Anybody knows please reply.

    modified on Friday, September 24, 2010 6:17 AM

    J 1 Reply Last reply
    0
    • S sr159

      I have a column called bookedhalls, the value will be stored as Balaji-A,Balaji-C, i written select query as follows Select * from function where bookedhalls like '%Balaji-A,Balaji-C,% by using this i will get the row. Suppose if i give '%Balaji-C,Balaji-A,%' i cannot get the row. How to get that row by using Balaji-C,Balaji-A. Anybody knows please reply.

      modified on Friday, September 24, 2010 6:17 AM

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      Your data model is fundamentally wrong, you should almost never be storing multiple values in one column with some delimiter (such as a comma). This is especially true if you need to query based on one of those multiple values. bookedhalls should be a separate table, referenced to the rest of that row using foreign key relationships, this would allow you to select based upon this join.

      S 1 Reply Last reply
      0
      • J J4amieC

        Your data model is fundamentally wrong, you should almost never be storing multiple values in one column with some delimiter (such as a comma). This is especially true if you need to query based on one of those multiple values. bookedhalls should be a separate table, referenced to the rest of that row using foreign key relationships, this would allow you to select based upon this join.

        S Offline
        S Offline
        sr159
        wrote on last edited by
        #3

        Actually i created table caolled function in that fun_start_date and fun_end_date and booked_halls collms is there. Suppose u conside one date it is booked for 2 floors (balaji-A, Balaji-B). User will select in forms. so i can write like select * from function where fun_start_date = 'date' and fun_end_date = 'date' and booked_halls like '%BALAJI-A,BALAJI-B,%' i will get the row. If there is no row means he can go for inserting. Here is Ok. Suppose user if select like first Balaji_B then Balaji-A in coding i will get string as a BALAJI-B,BALAJI-A. if i write like select * from function where fun_start_date = 'date' and fun_end_date = 'date' and booked_halls like '%BALAJI-B,BALAJI-A,%' i will not get the row . I should get that row. So nobody should not book for that floor. How to do this.

        J D M 3 Replies Last reply
        0
        • S sr159

          Actually i created table caolled function in that fun_start_date and fun_end_date and booked_halls collms is there. Suppose u conside one date it is booked for 2 floors (balaji-A, Balaji-B). User will select in forms. so i can write like select * from function where fun_start_date = 'date' and fun_end_date = 'date' and booked_halls like '%BALAJI-A,BALAJI-B,%' i will get the row. If there is no row means he can go for inserting. Here is Ok. Suppose user if select like first Balaji_B then Balaji-A in coding i will get string as a BALAJI-B,BALAJI-A. if i write like select * from function where fun_start_date = 'date' and fun_end_date = 'date' and booked_halls like '%BALAJI-B,BALAJI-A,%' i will not get the row . I should get that row. So nobody should not book for that floor. How to do this.

          J Offline
          J Offline
          J4amieC
          wrote on last edited by
          #4

          Did you actually read my response above? By fixing your data model, it fixes this issue.

          1 Reply Last reply
          0
          • S sr159

            Actually i created table caolled function in that fun_start_date and fun_end_date and booked_halls collms is there. Suppose u conside one date it is booked for 2 floors (balaji-A, Balaji-B). User will select in forms. so i can write like select * from function where fun_start_date = 'date' and fun_end_date = 'date' and booked_halls like '%BALAJI-A,BALAJI-B,%' i will get the row. If there is no row means he can go for inserting. Here is Ok. Suppose user if select like first Balaji_B then Balaji-A in coding i will get string as a BALAJI-B,BALAJI-A. if i write like select * from function where fun_start_date = 'date' and fun_end_date = 'date' and booked_halls like '%BALAJI-B,BALAJI-A,%' i will not get the row . I should get that row. So nobody should not book for that floor. How to do this.

            D Offline
            D Offline
            David Skelly
            wrote on last edited by
            #5

            As pointed out already, your table structure is not a good one, that is why you are finding it tricky to write this query. You should read up about database normalization. If you are really stuck with this data structure and cannot change it then you will need to do something like:

            select * from function where booked_halls like '%BALAJI_A%' and booked_halls like '%BALAJI_B%'

            But really you should change the data model because what you have at the moment is wrong.

            1 Reply Last reply
            0
            • S sr159

              Actually i created table caolled function in that fun_start_date and fun_end_date and booked_halls collms is there. Suppose u conside one date it is booked for 2 floors (balaji-A, Balaji-B). User will select in forms. so i can write like select * from function where fun_start_date = 'date' and fun_end_date = 'date' and booked_halls like '%BALAJI-A,BALAJI-B,%' i will get the row. If there is no row means he can go for inserting. Here is Ok. Suppose user if select like first Balaji_B then Balaji-A in coding i will get string as a BALAJI-B,BALAJI-A. if i write like select * from function where fun_start_date = 'date' and fun_end_date = 'date' and booked_halls like '%BALAJI-B,BALAJI-A,%' i will not get the row . I should get that row. So nobody should not book for that floor. How to do this.

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              Do NOT ignore the advice you have been given. Just because David has given you a work around FIX YOUR DATA STRUCTURE. If you do not do this NOW you will be back here continiously asking how to get at your data.

              Never underestimate the power of human stupidity RAH

              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