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'
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).
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.