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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:49:02+00:00 2026-06-18T22:49:02+00:00

I’m trying to run a query on a table (the one WordPress uses) where

  • 0

I’m trying to run a query on a table (the one WordPress uses) where I want to select the ID and post_type columns from one table, then do a Left Join to another table, two separate times (getting separate data).

This is what I have so far, but it’s not cutting the mustard:

SELECT derby_posts.id        AS pID, 
       derby_posts.post_type AS tier 
FROM   derby_posts 
       LEFT JOIN (SELECT derby_postmeta.post_id  AS dbID1, 
                         derby_postmeta.meta_key AS dbMeta1) 
              ON pid = dbid1 
                 AND dbmeta1 = 'twitter' 
       LEFT JOIN (SELECT derby_postmeta.post_id  AS dbID2, 
                         derby_postmeta.meta_key AS dbMeta2) 
              ON pid = dbid2 
                 AND dbmeta2 = 'website' 
WHERE  tier IN ('local', 'regional', 'national')

I’m sure I’m missing something super simple…

Edit: here’s the solution that worked for me. Table alias helped, putting all my SELECT statements together cleaned things up. Also, I realized I could remove items from the SELECT, even though I’m using them in the Join, which cleans up the results a lot.

SELECT 
    db.ID as id, 
    db.post_type as tier,
    dpm1.meta_value as twitter,
    dpm2.meta_value as website
FROM derby_posts db
LEFT JOIN derby_postmeta dpm1 ON (db.ID = dpm1.post_id AND dpm1.meta_key = 'twitter' )
LEFT JOIN derby_postmeta dpm2 ON (db.ID = dpm2.post_id AND dpm2.meta_key = 'website' )
WHERE db.post_type IN ('local','regional','national')
  • 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-18T22:49:04+00:00Added an answer on June 18, 2026 at 10:49 pm

    I ‘m sure I’m missing something super simple…

    You are right!

    You need to give your selects an alias, and use that alias in the ON clause. You are also missing a FROM <table> – a required part of a SELECT statement that reads from a table:

    LEFT JOIN (
        SELECT derby_postmeta.post_id  AS dbID1, 
               derby_postmeta.meta_key AS dbMeta1
        FROM someTable
    ) dpm ON pid = dpm.dbid1 AND dpm.dbmeta1 = 'twitter'
    

    I gave the results of your SELECT an alias dpm, and used it to “link up” the rows from the inner select to the rows of your outer select.

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

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to render a haml file in a javascript response like so:
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only

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.