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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:15:56+00:00 2026-05-25T03:15:56+00:00

I use the following query (in a PHP script) SELECT *, (SELECT head FROM

  • 0

I use the following query (in a PHP script)

SELECT *,
(SELECT head FROM pages WHERE id='0') AS nullhead
FROM pages WHERE id='$id1' OR id='$id2'

It pulls out data for a given page, including the value of the head column. However, the head column may be NULL, in which case the value for which id=0 is used instead.

Is it possible to do this without the subquery on line 2, while still using only one query?

  • 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-25T03:15:57+00:00Added an answer on May 25, 2026 at 3:15 am

    You want to do a self-join here (in this case, a cartesian self-join)

    select a.*, b.head as nullhead
    from pages a, pages b
    where a.id in ( '$id1', '$id2' )
    and b.id = '0'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the following query syntax from a php file: $sql =
for example i use following command to find a record SELECT `users`.`mail` FROM `users`
I'm trying to run the following PHP script to do a simple database query:
I use the following XPATH Query to list the object under a site. ListObject[@Title='SomeValue']
I use the following mysql query, DELIMITER $$ DROP PROCEDURE IF EXISTS `allied`.`aboutus_delete`$$ CREATE
The mysqltuner.pl script gives me the following recommendation: query_cache_limit (> 1M, or use smaller
I would like to use following sql to avoid constructing sql dynamically: SELECT CommentID,
I am working on a PHP project. There, I often use following syntax to
I use the following statement prepared and bound in ODBC: SELECT (CASE profile WHEN
I have the following pages: page1.php, page2.php and page3.php. Code in each of them

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.