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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:21:00+00:00 2026-05-12T17:21:00+00:00

This works if I remove the final JOIN line, but I’m not sure why

  • 0

This works if I remove the final JOIN line, but I’m not sure why it won’t work with it.
The last two JOIN statements are attempting to grab data (‘meta_value’) from different rows in the same table, the names of which can only be found by reading another corresponding column (‘meta_key’) in the same table. All this while joining everything on the user_id common in all 3 tables.

SELECT mod_membership.uid,
       mod_membership.wp_user_id,
       mod_membership.status,
       mod_membership.last_login,
       mod_membership.membership_type,
       mod_membership.membership_expiration,
       wp_users.user_login,
       wpm_a.meta_value AS first_name
  FROM mod_membership
  JOIN wp_users ON wp_users.ID = mod_membership.wp_user_id
  JOIN wp_usermeta AS wpm_a ON wpm_a.user_id = mod_membership.wp_user_id WHERE wpm_a.meta_key = 'first_name'
  JOIN wp_usermeta AS wpm_b ON wpm_b.user_id = mod_membership.wp_user_id WHERE wpm_b.meta_key = 'last_name'

How can I get this third JOIN to work, or use another method to get these results in a single result set, grouped on user_id?

  • 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-12T17:21:00+00:00Added an answer on May 12, 2026 at 5:21 pm

    try this:

     SELECT m.uid, m.wp_user_id,m.status,
         m.last_login,m.membership_type,
         m.membership_expiration,
         u.user_login,
         f.meta_value first_name,
         l.meta_value last_name
    From mod_membership m
       Join wp_users u 
          On u.ID = m.wp_user_id
       Left Join wp_usermeta f
          On f.user_id = m.wp_user_id
             And f.meta_key = 'first_name'
       Left Join wp_usermeta l
          On l.user_id = m.wp_user_id
             And l.meta_key = 'last_name'
    

    To answer your question the reason your syntax was not working is, first of all, there can be only one where clause per sql statement. You can’t add a where clause for each join, that’s what the “On” cluase is for…

    Secondly, the conditions in that Where clause are not applied until the final resultset has been generated, whereas join conditions are evaluated “along the way” as each intermediate result set is constructed from each successive join statement.

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

Sidebar

Related Questions

This works, but is it the proper way to do it??? I have a
First, two examples: // This works int foo = 43; long lFoo = foo;
I am using Delphi TApplication.OnException Event to catch unhandled exceptions This works well but
I've been doing some HTML scraping in PHP using regular expressions. This works, but
This works (prints, for example, 3 arguments): to run argv do shell script echo
This works just fine: protected void txtTest_Load(object sender, EventArgs e) { if (sender is
Could someone explain why this works in C#.NET 2.0: Nullable<DateTime> foo; if (true) foo
I ran across this and was wondering if someone could explain why this works
I was kind of shocked by this. Could someone explain why this works? A
I'm using Mongrel::DirHandler to control response headers for static files - this works great

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.