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. Multiple column with in keyword

Multiple column with in keyword

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

    Hi My table has composite pk, when i want to select based on one key i write select * from table where col1 = 'val1' and col2 = 'val2' when i have more then one pk like (val1, val2), (val3, val4), ... how can i write select with in so that i can get rows satisfing all the conditions. Shajeel

    P R 2 Replies Last reply
    0
    • S Shajeel

      Hi My table has composite pk, when i want to select based on one key i write select * from table where col1 = 'val1' and col2 = 'val2' when i have more then one pk like (val1, val2), (val3, val4), ... how can i write select with in so that i can get rows satisfing all the conditions. Shajeel

      P Offline
      P Offline
      Paddy Boyd
      wrote on last edited by
      #2

      select * from table where col1 in ('val1', 'val2') and col2 in ('val3', 'val4')

      S 1 Reply Last reply
      0
      • P Paddy Boyd

        select * from table where col1 in ('val1', 'val2') and col2 in ('val3', 'val4')

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

        if will give me four combinations val1 and val3 val1 and val4 val2 and val3 val2 and val4 but i want only two combinations like here i just want first and third condition. Shajeel

        R 1 Reply Last reply
        0
        • S Shajeel

          Hi My table has composite pk, when i want to select based on one key i write select * from table where col1 = 'val1' and col2 = 'val2' when i have more then one pk like (val1, val2), (val3, val4), ... how can i write select with in so that i can get rows satisfing all the conditions. Shajeel

          R Offline
          R Offline
          Rana Muhammad Javed Khan
          wrote on last edited by
          #4

          you can simply use: select * from table where col1 IN('val1' , 'val2') and col2 IN ('val3' , 'val4') it will work... Javed

          1 Reply Last reply
          0
          • S Shajeel

            if will give me four combinations val1 and val3 val1 and val4 val2 and val3 val2 and val4 but i want only two combinations like here i just want first and third condition. Shajeel

            R Offline
            R Offline
            Rana Muhammad Javed Khan
            wrote on last edited by
            #5

            you put dummy data in table then check the query will work fine...

            S 1 Reply Last reply
            0
            • R Rana Muhammad Javed Khan

              you put dummy data in table then check the query will work fine...

              S Offline
              S Offline
              Shajeel
              wrote on last edited by
              #6

              suppose i have a table Color Shape Red Cirle Red Square Yellow Square and i want 2 records of (Red, Circle) and (Yellow, Square) your command will return me 3 records out of which i dont want middle one. Thank for taking interest Shajeel

              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