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

  • Home
  • SEARCH
  • 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 8749431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:41:39+00:00 2026-06-13T12:41:39+00:00

Basically I have 2 tables. Lets say A and B. A has columns like

  • 0

Basically I have 2 tables. Lets say A and B.

A has columns like id(PK), pin, name, address

id(PK)  pin             name    address
1        aaa-111-aaa    AAA ------
2        bbb-222-bbb    BBB ------
3        ccc-333-ccc    CCC --------

B has columns like appName, apprequestTime, appAccectTime, id(FK).

appName apprequestTime  appAccectTime    id(FK).
LLL          2012-4-01  2012-4-01    1
NNN          2012-4-08  2012-5-01    2
QQQ          2012-4-05  2012-4-01    1
MMM          2012-4-02  2012-4-02    2
PPP          2012-5-01  2012-5-01    1

There can be multiple id rows in the B table as it is Foreign Key.

Now, the problem is I am trying to get all the records of one pin of a certain apprequestTime.

I am trying inner join but it shows the pin because of the id in table B.

pin         apprequestTime
aaa-111-aaa     2012-4-01
aaa-111-aaa     2012-4-05
bbb-222-bbb     2012-4-08
bbb-222-bbb     2012-4-02

but the result I am expecting should be:

pin            apprequestTime
aaa-111-aaa    2012-4-01
               2012-4-05
bbb-222-bbb    2012-4-08
               2012-4-02

Can any one help:)

  • 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-13T12:41:40+00:00Added an answer on June 13, 2026 at 12:41 pm

    In SQL Server 2005+ you can use row_number() for this type of request:

    ;with cte as
    (
      select a.pin, b.apprequestTime,
        row_number() over(partition by a.pin 
                          order by b.apprequestTime) rn
      from tablea a
      inner join tableb b
        on a.id = b.id
    ) 
    select case when rn = 1 then pin else '' end pin, 
      apprequestTime
    from cte;
    

    See SQL Fiddle with Demo

    Or without CTE:

    select case when rn = 1 then pin else '' end pin, 
      apprequestTime
    from 
    (
      select a.pin, b.apprequestTime,
        row_number() over(partition by a.pin 
                          order by b.apprequestTime) rn
      from tablea a
      inner join tableb b
        on a.id = b.id
    ) t1
    

    See SQL Fiddle with Demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have two tables, employee and department where emp has a @ManyToOne
Lets say I have 2 tables: blog_posts and categories. Each blog post belongs to
So lets say I have a table that looks something like this: ItemName ProductType
Lets say I have your basic table layout (like below). How to I grab
Let's say I have these tables/models: Product - id - last_updated_date - name -
I have a html table which has several rows - lets say 17 for
I currently have a database with two tables in it one hold lets say
Lets say I have two tables - Person and Clothes and both of these
I have a table like these: Club Table contains: ClubID(IDENTITY), Name, Address Genre table
I basically have three tables, posts, images and postimages (this simply contains the ids

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.