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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:47:41+00:00 2026-05-19T01:47:41+00:00

This is a wordpress installation, but I think the question is more of a

  • 0

This is a wordpress installation, but I think the question is more of a general sql question. First off, my sql skills are not great (I don’t even know if I’m following the correct format for illustrating the db).

I’ve got two tables:

wp_posts :

    ID (pk)  |   post_name  |  ...
----------------------------
    45       |    "Hello"
    91       |    "Funny"
    16       |    "Wheat"

wp_postmeta :

    post_id (fk)  |    meta_key      |   meta_value  | ...
------------------------------------------------
    45            |    "_edit_lock"  |   5789789834
    45            |    "fizzbizz"    |   "foobar"
    91            |    "_something"  |   "teve"

I would like to select all rows in wp_posts where there is NO corresponding row in wp_postmeta where meta_key = “fizzbizz”

I originally had this query, but someone pointed out that it would not retrieve ID = ’16’ in the above case. How would I correctly write the query?

$pageposts = $wpdb->get_results("
    SELECT * FROM wp_posts p 
    JOIN wp_postmeta m 
    ON p.ID = m.post_id 
    WHERE m.meta_key <> 'fizzbizz' 
    ORDER BY p.post_date DESC;
");
  • 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-19T01:47:42+00:00Added an answer on May 19, 2026 at 1:47 am

    Use your current query with the following changes:

    LEFT JOIN instead of JOIN

    add

    OR m.metakey IS NULL to your WHERE clause:

    SELECT * FROM wp_posts p 
        LEFT JOIN wp_postmeta m 
        ON p.ID = m.post_id 
        WHERE m.meta_key <> 'fizzbizz'
           OR m.metakey IS NULL
        ORDER BY p.post_date DESC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've tagged this post as WordPress, but I'm not entirely sure it's WordPress-specific, so
I'm cross-posting this from the wordpress section, b/c I think the problem lies more
I had this Wordpress installation which was installed in a subfolder (not root). Like
First off I have gone through this link http://codex.wordpress.org/Integrating_WordPress_with_Your_Website . I cannot use this.
I'm using this code with success on some wordpress installation, but with my new
Disclaimer: not sure this is WordPress related or not. I'm following a simple tutorial
This deals with WordPress plugin development. Even if a user has not actually signed
I am familiar with previous Wordpress installers, but in this new version I've hit
I'm not really fit in wordpress but a friend of mine asked me to
I am trying to rewrite http://www.domain to http://domain in a wordpress installation, but it

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.