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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:55:31+00:00 2026-06-03T06:55:31+00:00

I have the following tables: TableT1 TableT2 id name mid id visitdate 4 jack

  • 0

I have the following tables:

   TableT1                             TableT2

id           name                 mid  id    visitdate       
4            jack                  1   4     2012/01/22          
5            john                  2   5     2012/01/21            
6            mary                  3   6     Null   
                                           4   5     2012/02/21

I have join this two table.. for each “id” I have to show only one record if he has multiple visit date..

Using below query I m getting record as I want

 select id,name 
 from TableT1 
 left join
 ( 
   SELECT  id,MAX(visitdate) AS visitdate 
   FROM TableT2 
   GROUP BY id
 )as Last_Visit on TableT1.id=Last_Visit.id 
 order by TableT1.name,Last_Visit.visitdate Desc

My problem is to find out rownumber for each id(coloumn) and chk in condition RowNumber >=1 AND RowNumber<=3.

  • 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-03T06:55:33+00:00Added an answer on June 3, 2026 at 6:55 am

    This should give you only the last visitdate per id and only if this id has multiple visits.

    WITH cte AS(
        SELECT id
        , visitdate 
        , ROW_NUMBER()OVER(Partition By id Order By visitdate DESC)As VisitNum
       FROM TableT2 
    )
    select  TableT1.id, TableT1.name
           ,cte.visitdate , cte.VisitNum
     from TableT1 INNER JOIN cte 
        ON TableT1.id=cte.id  AND cte.VisitNum=1 
            AND EXISTS(SELECT NULL FROM cte c2 WHERE c2.id=cte.id AND c2.VisitNum>1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following 3 tables table1 id name ---------- 1 john 2 dave
Say I have the following 2 tables, CREATE TABLE t1( name VARCHAR(25) NOT NULL,
I have the following two tables: Table1 ---------- ID Name 1 A 2 B
I have the following tables Pedal Brand:string Classification:string Model:string Variety Title:string name:string pedal_id:integer Example
I have two tables and the following query: table1 --------- table1Id(pk) fromdate, todate, name,
I have the following 3 tables Table1 ID | NAME ----------- 1 | X
I have two tables that have following rows: Table1 ID Name Number ===================== 1
I have following databases: test table1 fields: id, password, name, lastname test2 table2 fields:
I have the following MySQL query statement: SELECT * FROM table1 INNER JOIN table2
I have two tables with the following columns: table1: id, agent_name, ticket_id, category, date_logged

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.