simpe sql squery
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: simpe sql squery

  1. #1
    Join Date
    May 2002
    Posts
    6
    Hi

    I have simple doubt in sql statement .
    I have column from a table where column name = ANO AND ITS VALUE IS 5 ( ANO = 5) and i need to match this
    column with other five columns in other table ( AN1,AN2AN3,AN4,AN5) and all these columns should have the same value
    it should be like this

    select count(*)
    from temp
    where ano=an1
    ano=an2
    ano=an3
    ano=an4
    ano=an5
    Is there any alternate way where we can match One column value with all the other five coulmns

    Thanks
    lnr


  2. #2
    Join Date
    Jan 2001
    Location
    San Diego, CA
    Posts
    81
    select count(*)
    from temp
    where ano in (an1,an2,an3,an4,an5)

    Eugene
    OCP
    San Diego

  3. #3
    Join Date
    Apr 2001
    Location
    Czechia
    Posts
    712
    I think there's nothing wrong with this:
    Code:
    select count(*) 
    from temp 
    where ano=an1 
    AND ano=an2 
    AND ano=an3 
    AND ano=an4 
    AND ano=an5
    eugene:
    Code:
    select count(*) 
    from temp 
    where ano in (an1,an2,an3,an4,an5)
    does not work. We can rewrite the IN() clause as "ano=an1 OR ano=an2 OR ano=an3 ... "
    so the condition is true if AT LEAST ONE an? is equal to ano. But lnreddy needs to have ALL an? equal to ano.
    Ales
    The whole difference between a little boy and an adult man is the price of toys

Posting Permissions

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



Click Here to Expand Forum to Full Width