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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:19:57+00:00 2026-05-28T08:19:57+00:00

I am working in a MySQL database. I have added a custom field to

  • 0

I am working in a MySQL database.

I have added a custom field to a WordPress database called “short_url”

I want a list of all posts in the database along with the value for “short_url” if the post has that value. But I want all of the posts nonetheless. I have composed the following query and used a LEFT join so that I get back all posts even if there is no corresponding custom value, but it is not working.

SELECT
    wp_posts.post_title
    , wp_posts.post_date
    , wp_postmeta.meta_value
FROM
    wp_posts
    LEFT JOIN wp_postmeta
        ON ( wp_posts.ID = wp_postmeta.post_id)
WHERE (wp_postmeta.meta_key ="short url");

This query returns 12 results, which is how many articles have the custom value, but there are 193 posts in my database.

Why I am getting back is a list of only posts that have the “short_url” value?

How can I get a full list?

  • 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-28T08:19:58+00:00Added an answer on May 28, 2026 at 8:19 am

    You need to move the condition from the WHERE clause to the ON clause. Conditions in a WHERE clause affect all of the results. Conditions in the ON clause affect the JOIN.

    SELECT
        wp_posts.post_title,
        wp_posts.post_date,
        wp_postmeta.meta_value
    FROM
        wp_posts
        LEFT JOIN wp_postmeta
            ON (wp_posts.ID = wp_postmeta.post_id) AND
               (wp_postmeta.meta_key ="short url");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP site with a mySQL database that I'm working on. I'm
I have a working PHP server. Now I want to use databases (MySQL or
I have been working on a mysql database that I set up with phpmyadmin...
I have a working pdo integrated database class. All of my queries are working
I have a java program that connects to a MySql database and it's working
I'm working with a MySQL database that has some data imported from Excel .
I am working on a MySQL database that is huge (about 120 tables). I
I am working with a rather large mysql database (several million rows) with a
I'm currently working on a PHP application that uses a MySQL database for its
I'm working on a database with mysql 5.0 for an open source project it's

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.