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 6855007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:42:14+00:00 2026-05-27T01:42:14+00:00

This is my table: ID COUNTRY_CODE_3D COUNTRY_CODE_2D TYPE_ID 1 IND IN 11 2 CAN

  • 0

This is my table:

ID      COUNTRY_CODE_3D     COUNTRY_CODE_2D      TYPE_ID    
 1          "IND"            "IN"                  11           
 2          "CAN"            "CA"                  13           
 3           null            null                  17

I want a select query which will return a single row 
if COUNTRY_CODE_2D = 'CA' (valid data) return 2nd row, else return the 3rd row where COUNTRY_CODE_2D =null and TYPE_ID=17

  • 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-27T01:42:15+00:00Added an answer on May 27, 2026 at 1:42 am

    If you can put a functional index on country_code_2d, (NVL(country_code_2d,'EMPTY') )

    CREATE INDEX fidx_empty_null ON country_cnfg_tbl (NVL(country_code_2d,'EMPTY'));
    

    ,you can then

    SELECT * FROM country_cnfg_tbl a
    WHERE NVL(a.country_code_2d,'EMPTY') IN 
    (  
        SELECT NVL(b.country_code_2d,'EMPTY') FROM dual d
        LEFT JOIN country_cnfg_tbl b on b.country_code_2d = 'CA'
    )
    

    Or Without joins (and more portable as it does not use the oracle table DUAL)

    SELECT * FROM country_cnfg_tbl a WHERE NVL(a.country_code_2d,'EMPTY') IN  
    (       
        SELECT CASE WHEN count(*) = 0 THEN 
                    'EMPTY' 
               ELSE 
                    b.country_code_2d 
               END as country_code_2d  
        FROM country_cnfg_tbl b 
        WHERE b.country_code_2d = 'CA'
        GROUP BY b.country_code_2d
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this table i want to create job_id dynamic Jobs Title text Job Description text
Got this: Table a ID RelatedBs 1 NULL 2 NULL Table b AID ID
I have this table in an Oracle DB which has a primary key defined
I want to load this array as table in Smarty. Array: Array ( [0]
I have this sql query retrieving IDs from a table with 3 columns: ID,
I currently am returning a table that looks like this: Country Result ------ -----
This table is used to store sessions (events): CREATE TABLE session ( id int(11)
In this table how would I use YQL/Xpath to get all data members of
Consider this table on SQL Server wordID aliasID value =========================== 0 0 'cat' 1
Say I have this table: Person table -------------- PersonId Address table ------------ AddressId PersonAddressId

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.