SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    conditional reults in a query

    Hi all

    My db structure is (table r)

    id,a,b,c
    1,1,1,USA
    2,1,2,national
    3,1,3,USA



    I a m looking for a query which satisfy a=1 and c=usa.If 'USA' is not avilable I need to get second row (national).How can I do this in mysql ? and If USA is avilable I need only first and third row.

    Is it poosible to get in a single query,please help

    I tried this but not getting exact results


    select * from r where a = 1 and
    (


    CASE
    WHEN (c = 'USA')
    THEN
    c= 'USA

    ELSE c = 'national'





    END


    )

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,247
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by aniltc View Post
    If 'USA' is not avilable I need to get second row (national).
    rows in a database table don't have positions, so "second" is not possible

    is there some other way to determine which row(s) you want if USA is not available?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    solution stored procedure


Bookmarks

Posting Permissions

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