Results 1 to 6 of 6

Thread: SQL query

  1. #1
    Join Date
    Dec 2007
    Posts
    1

    SQL query

    Hi,
    I have a table storing data like this

    Oid OKey OValue
    1 Status Open
    1 Priority 1
    1 Name TTT
    1 Location NYC
    2 Status Open
    2 Priority 2
    2 Name TYY
    2 Location WDC
    3 Status Close
    3 Priority 2
    3 Name TYZ
    3 Location WDC

    Now, I need to write a query to fetch Oid’s with Okey Priority=”2” and Okey Location=”WDC”

    Kindly suggest

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    Select * from table where (okey = 'Priority' and ovalue = '2') and (okey = 'Location' and ovalue = 'WDC')

  3. #3
    Join Date
    Dec 2007
    Posts
    2
    1. SELECT * FROM TABLENAME WHERE Priority=2 AND Location='WDC'

  4. #4
    Join Date
    Sep 2002
    Posts
    5,938
    In this case, Priority and Location are values in column okey. WDC and 2 are values of ovalue column.

  5. #5
    Join Date
    Dec 2007
    Posts
    2
    Let me show your table structure with values
    Its easier for me to expalin.

    Cool

  6. #6
    Join Date
    Dec 2011
    Location
    Austria
    Posts
    6

    SQL query

    Not knowing the database structure means that it will be impossible to give a precise answer, but in general
    Open SQL Server Management Studio
    Click the NEW QUERY button
    Type USE <name of database>
    Click Execute
    Type SELECT FROM <name of table containing client list>
    Click Execute

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •