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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:32:45+00:00 2026-06-04T03:32:45+00:00

Hi am new to Teradata and am stuck with a problem There is an

  • 0

Hi am new to Teradata and am stuck with a problem

There is an ID table which stores an Unique ID given to each person

CREATE TABLE IDS(
ID VARCHAR(8),
UPDATED_DATE DATE)

Then we have a name and address table which do not have any primary keys that stores demographic information for the IDS

CREATE TABLE NAMES(
ID VARCHAR(8),
NAME VARCHAR(50))
CREATE TABLE ADRRESSES(
ID VARCHAR(8)
ADDRESS VARCHAR(200))

Now each ID can have multiple name and IDS. However for names and address I want to use the ones that are have more counts. If two names have the same COUNT I just want the First row

ID NAME COUNT

1234 John Smith 6

1234 Johnnie Smith 6

1234 J Smith 2

In the above example I want the name John Smith. Here is the left Join I am performing since an ID may not have a name or address. Here is what I am trying

SELECT * FROM
(SELECT ID as V_ID from IDS) a
LEFT JOIN
(SELECT ID, NAME, COUNT(*) AS COUNTER,(RANK() OVER(ORDER BY COUNTER DESC)) AS RNK
FROM NAMES 
GROUP BY ID)b
ON a.ID = b.ID
AND b.RNK = 1            -- Should give me only the first row
LEFT JOIN
(SELECT ID, ADDRESS, COUNT(*) AS COUNTER, (RANK() OVER (ORDER BY COUNTER DESC) ) AS RNK
FROM ADDRESSES
GROUP BY ID) c
ON c.ID = a.ID
And c.RNK = 1

However this is not getting me the desired result. I tried using ROW NUMBER instead of RANK also but still no results. How should I write this query in TERDATA?

  • 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-04T03:32:46+00:00Added an answer on June 4, 2026 at 3:32 am

    I solved it …I needed a qualify and a partition by

    SELECT * FROM
        (SELECT ID as V_ID from IDS) a
        LEFT JOIN
        (SELECT ID, NAME, COUNT(*) AS COUNTER
        FROM NAMES
        GROUP BY ID
        qualify ROW_NUMBER() OVER(PARTITION BY ID ORDER BY COUNTER DESC) = 1
        )b
        ON a.ID = b.ID
        LEFT JOIN
        (SELECT ID, ADDRESS, COUNT(*) AS COUNTER
        FROM ADDRESSES
        GROUP BY ID
        qualify ROW_NUMBER() OVER(PARTITION BY ID ORDER BY COUNTER DESC) = 1
        ) c
        ON c.ID = a.ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NEW EDIT: I have narrowed my problem to this - i have a view
New to Ruby and ROR and loving it each day, so here is my
New to MonoTouch and MonoTouch.Dialog, but I'm sure it's possible to create a tab
New Android programmer here. I have a Service which performs socket management and async
New to StackOverflow here. I'm working on the first Euler problem and have run
New list items are generated by JS. Each new list item comes in with
New to Tortoise SVN Source Safe Repository. I have ASP.Net web application which i
New to iPhone app development, I have a problem compiling (or Build and Run)
New Android developer here; well versed in Java. I'm looking to create a playlist
New to DDD here and have a architecture question which should be a typical

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.