Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6663775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:32:10+00:00 2026-05-26T02:32:10+00:00

I have a table like the following : ID |INFO | DATE_DT ————————- 1091|info5

  • 0

I have a table like the following :

ID  |INFO     | DATE_DT
-------------------------
1091|info5    |10/10/2010
1239|old.info |14/09/2010
1340|old.info |07/10/2010
3481|info     |16/10/2010
4134|info3    |21/01/2011

i would like to display just one row with the following conditions :
– if i have in my table one row with INFO = 'info' –> display just this row
– if i dont have one row with INFO = 'info' so i –> display the row with INFO = 'old.info' and DATE_DT = MAX(DATE_DT)

so, in my example if my table is :

ID  |INFO     | DATE_DT
-------------------------
1091|info5    |10/10/2010
1239|old.info |14/09/2010
1340|old.info |07/10/2010
3481|info     |16/10/2010 ===> display this row
4134|info3    |21/01/2011

or if my table doesnt containt INFO = ‘info’

ID  |INFO     | DATE_DT
-------------------------
1091|info5    |10/10/2010
1239|old.info |14/09/2010
1340|old.info |07/10/2010 ===> display this row
4134|info3    |21/01/2011

any suggestions?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:32:11+00:00Added an answer on May 26, 2026 at 2:32 am

    You could select both row and take by priority the one that satisfies the first condition:

    SQL> WITH my_table AS (
      2  SELECT 1091 id, 'info5' info, to_date('10/10/2010') date_dt FROM DUAL
      3  UNION ALL SELECT 1239, 'old.info' , to_date('14/09/2010') FROM DUAL
      4  UNION ALL SELECT 1340, 'old.info' , to_date('07/10/2010') FROM DUAL
      5  UNION ALL SELECT 3481, 'info'     , to_date('16/10/2010') FROM DUAL
      6  UNION ALL SELECT 4134, 'info3'    , to_date('21/01/2011') FROM DUAL)
      7  SELECT * FROM (
      8     SELECT 1 ord, t.*
      9       FROM my_table t
     10      WHERE info = 'info'
     11     UNION ALL
     12     SELECT 2 ord, t.*
     13       FROM my_table t
     14      WHERE date_dt = (SELECT MAX(date_dt) FROM my_table)
     15     ORDER BY ord)
     16   WHERE ROWNUM = 1;
    
           ORD         ID INFO     DATE_DT
    ---------- ---------- -------- -----------
             1       3481 info     16/10/2010
    

    If you remove the row 'info', the row where DATE_DT = MAX(DATE_DT) will be chosen:

    SQL> WITH my_table AS (
      2  SELECT 1091 id, 'info5' info, to_date('10/10/2010') date_dt FROM DUAL
      3  UNION ALL SELECT 1239, 'old.info' , to_date('14/09/2010') FROM DUAL
      4  UNION ALL SELECT 1340, 'old.info' , to_date('07/10/2010') FROM DUAL
      5  /*UNION ALL SELECT 3481, 'info'     , to_date('16/10/2010') FROM DUAL*/
      6  UNION ALL SELECT 4134, 'info3'    , to_date('21/01/2011') FROM DUAL)
      7  SELECT * FROM (
      8     SELECT 1 ord, t.*
      9       FROM my_table t
     10      WHERE info = 'info'
     11     UNION ALL
     12     SELECT 2 ord, t.*
     13       FROM my_table t
     14      WHERE date_dt = (SELECT MAX(date_dt) FROM my_table)
     15     ORDER BY ord)
     16   WHERE ROWNUM = 1;
    
           ORD         ID INFO     DATE_DT
    ---------- ---------- -------- -----------
             2       4134 info3    21/01/2011
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table like the following: RuleStep StepID | Step Property | Step
I have a table like the following: ID Output ------------------------- 01ABC1 AB 01ABC2 AB
Say I have a database table like the following: FileID | FileName | FileSize
Let's say I have following table like this <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0
In SQL Server 2008 I have a user table like the following: Userid Username
I have a table that looks like the following: <table class=theClass> <tr> <td class=anotherClass><strong>Label1:</strong></td>
i have a table in sqlite database like following. id status ============= x 0
I have a table in MySQL That looks like the following: date |storenum |views
I have a MySQL table with a structure like the following: I'm looking for
I have a string like following: CREATE GLOBAL TEMPORARY TABLE some_temp_table_name or CREATE GLOBAL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.