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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:44:58+00:00 2026-06-12T22:44:58+00:00

I am trying to join two tables: table A and table B. Table A

  • 0

I am trying to join two tables: table A and table B. Table A has unique ID’s for each row and has corresponding ID’s in Table B but in Table B the ID’s can appear multiple times.

Whenever I try an inner join I get duplicate rows because of table B so I’m wondering how I can join without having those duplicates.

Basically I only want one record from Table B for each row of Table A but its not happening.

edit:

SELECT p.post_title, tt.cntaccess FROM wp_posts as p INNER JOIN wp_top_ten as tt ON p.ID = tt.postnumber WHERE p.post_date > '2000-01-02 00:00:00' AND tt.cntaccess > '10'

  • 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-12T22:45:00+00:00Added an answer on June 12, 2026 at 10:45 pm

    This will join a with the corresponding b having the latest date and if there are multiple b’s matching that criteria, the b with the highest id. b.id and a.id are assumed to be unique (or primary key).

    SELECT a.id
         , b.id
         , b.date
      FROM a
      JOIN b
        ON a.id = b.a_id
      LEFT JOIN b AS b2
        ON b.a_id = b2.a_id
       AND (b.date, b.id) < (b2.date, b2.id)
     WHERE b2.id IS NULL
    ;
    

    Here’s my attempt to use your tables with your logic. Note that I refer to tt.pk. This pk represents a unique or primary key for the intended behavior. You didn’t show enough detail to know this information. I haven’t tested the following SQL. The above test SQL has been tested.

    SELECT p.post_title
         , tt.cntaccess
         , p.ID
         , tt.pk 
      FROM wp_posts AS p
      JOIN wp_top_ten AS tt
        ON p.id = tt.postnumber 
       AND tt.cntaccess > '10'
      LEFT JOIN wp_top_ten as tt2
        ON tt.postnumber = tt2.postnumber 
       AND tt2.cntaccess > '10'
       AND (tt.date, tt.pk) < (tt2.date, tt2.pk) 
     WHERE tt2.postnumber IS NULL 
       AND p.post_date > '2000-01-02 00:00:00'
    ; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to compare two tables to find rows in each table that
I'm trying to join two table (call them table1 and table2) but only return
I'm trying to generate a SQL query that can join two tables together and
I am trying to join data from two tables where the userid from table
I'm trying to join two relatively simple tables together, but my query is experiencing
I have been trying to join two tables (USERS AND USERS_ROLES) based on their
I am trying to join two tables; the purpose being able to search and
I am currently using Symfony2 and Doctrine2 and am trying to join two tables
I'm relatively new SQL queries, and I'm trying to join two tables in order
I'm trying to LEFT JOIN two tables, to get a list of all rows

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.