How to select same column twice with different condition?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Umesh Anant
    New Member
    • Dec 2010
    • 2

    How to select same column twice with different condition?

    Hi,

    I have a table which have three fields.

    The three columns are:
    username lastname Timestamp

    Now I have to fetch all the entries for username separately which have lastname as 'Hello' and timestamp for last six months. I need both the data in separate rows.

    Thanks,
    Umesh
  • amitpatel66
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #2
    Can you post what you have tried so far?

    Comment

    • Umesh Anant
      New Member
      • Dec 2010
      • 2

      #3
      select password from table1 where user_id = ? AND password in (SELECT password FROM table1 where user_id = ? AND TO_CHAR(passwor d_set_date, 'dd-mon-yyyy hh24:mi:ss') < TO_CHAR(CURRENT _DATE, 'dd-mon-yyyy hh24:mi:ss') AND TO_CHAR(add_mon ths (sysdate, -6), 'dd-mon-yyyy hh24:mi:ss') >TO_CHAR(passwo rd_set_date, 'dd-mon-yyyy hh24:mi:ss'))

      I need data for last six times separately and for last six months separately!

      Comment

      • amitpatel66
        Recognized Expert Top Contributor
        • Mar 2007
        • 2358

        #4
        Can you try this:

        [code=oracle]
        select password from table1 where user_id = ? AND password in (SELECT password FROM table1 where user_id = ? AND TO_CHAR(passwor d_set_date, 'dd-mon-yyyy hh24:mi:ss') < TO_CHAR(CURRENT _DATE, 'dd-mon-yyyy hh24:mi:ss')
        UNION ALL
        select password from table1 where
        password_set_da te BETWEEN ADD_MONTHS(SYSD ATE,-6) AND SYSDATE
        [/code]

        Comment

        Working...