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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:30:30+00:00 2026-06-09T08:30:30+00:00

I got a table like this AMID Entry ——- ——— 1000 MARS 1001 JUPITER

  • 0

I got a table like this

AMID     Entry
------- ---------
1000     MARS
1001     JUPITER
1002     SATURN
1003     VENUS
1003     SATURN
1004     NEPTUNE
1004     SATURN
1005     JUPITER
1005     MARS

Now I want to extract the DISTINCT AMID values with particular ENTRY values.
The end table should be like this

 AMID     Entry
-------- --------
  1000    MARS
  1001    JUPITER
  1002    SATURN
  1003    VENUS
  1004    SATURN
  1005    MARS

The condition to select ENTRY values is,

It has to take the values based on this priority :

  1. VENUS
  2. MARS
  3. JUPITER
  4. SATURN
  5. NEPTUNE

So If any AMID has both VENUS and MARS, it should take VENUS
MARS and SATURN, it should take MARS
NEPTUNE and JUPITER, it should take JUPITER.(select by priority).

  • 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-06-09T08:30:32+00:00Added an answer on June 9, 2026 at 8:30 am

    You can do it with ranking functions (if you’re using SQL Server 2008):

    DECLARE @t TABLE (AMID INT, Entry VARCHAR(100))
    INSERT @t 
    VALUES
    (       1000                   ,'MARS'),
    (       1001                   ,'JUPITER'),
    (       1002                   ,'SATURN'),
    (       1003                   ,'VENUS'),
    (       1003                   ,'SATURN'),
    (       1004                   ,'NEPTUNE'),
    (       1004                   ,'SATURN'),
    (       1005                   ,'JUPITER'),
    (       1005                   ,'MARS')
    
    ;WITH a AS(
        SELECT  *,
                ROW_NUMBER() OVER (PARTITION BY AMID ORDER BY 
                    CASE Entry 
                        WHEN 'VENUS' THEN 0
                        WHEN 'MARS' THEN 1
                        WHEN 'JUPITER' THEN 2
                        WHEN 'SATURN' THEN 3
                        WHEN 'NEPTUNE' THEN 4
                    END) num
        FROM    @t
    )
    
    SELECT  AMID, Entry
    FROM    a
    WHERE   num = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a table like this, and use MYSQL 5.5 id --- 2 3
I've got table with two columns: name and grade. It looks sth like this:
I've basically got a table with 2 rows and it looks like this: ---------
I'm relatively confused about this... I've got a table like: +----------------+--------------------------------------------------+------+-----+-------------------+-----------------------------+ | Field |
I've got a situation like this: Table: FunTable ItemKey ItemName ItemPriceEffectiveDate ItemPrice 11 ItemA
So I've got this audit table, looks like this: USE [DatabaseName] GO /****** Object:
I've got m2m relationship like this: #main table CREATE TABLE products_product ( id integer
I've got a query that looks something like this: SELECT * FROM table WHERE
I’ve got a table like this: Create Table PersonAgent ( PersonID varchar2(10) not null,
Let's say you've got a table like this: ID Cat1 Cat2 1 a red

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.