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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:52:15+00:00 2026-05-23T02:52:15+00:00

I am running an SQL statement: $sql = SELECT pic, userid FROM user_details INNER

  • 0

I am running an SQL statement:

$sql = "SELECT pic, userid 
        FROM user_details 
          INNER JOIN wp_users ON user_details.userid  
        WHERE wp_users.id = user_details.userid 
        LIMIT $recordstart, $pagesize
       ";

The query is meant to select records from user_details and wp_users, but should only select if there is a match (wp_users.id = user_details.userid).

The target is for it to basically select from a table while retrieving a record (based on the id match) from the other table

The problem is that it shows duplicate records. How can I fix this problem?

  • 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-05-23T02:52:16+00:00Added an answer on May 23, 2026 at 2:52 am

    You should put your JOIN condition after ON. Like this:

    $sql="select pic, userid 
          from user_details 
          inner join wp_users on (wp_users.id=user_details.userid)
          limit $recordstart, $pagesize";
    

    But the real problem is that you have more then 1 record in user_details for each corresponding record in wp_users (or vise versa).
    INNER JOIN is causing database to make a Cartesian product of user_details and wp_users records. Then result table is filtered by your current WHERE condition (wp_users.id=user_details.userid). Depends on your needs you can use GROUP BY or DISTINCT if you want to retrieve unique records only.
    For example, if you need userid to be unique:

    $sql="select pic, userid 
          from user_details 
          inner join wp_users on (wp_users.id=user_details.userid)
          group by userid
          limit $recordstart, $pagesize";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SELECT * FROM [makes$] WHERE Corporate Name='Champion Enterprises, Inc.' I'm running this query on
In Sql Server 2000 and 2005 I am running a select statement in a
I have this sql statement: SELECT game.game_id FROM game, userGame WHERE userGame.user_id = 1
Problem On a DB2 (version 9.5) the SQL statement SELECT o.Id FROM Table1 o,
I have a T-Sql Statement as follows; Insert into Table1 Select * From Table2
I have an weird issue, I am running the following SQL statement: SELECT *
I have this query in my sql if (select count(*) from sys.columns where object_id
An SQL statement like: select * from ( select '000000000000' as x from dual
I have a long running SQL statement that I want to run, and no
I am running an Execute SQL Task statement in my SSIS package. The Execute

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.