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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:16:26+00:00 2026-05-13T11:16:26+00:00

My query is throwing an error like select id,cHospital from med_patient where cHospital is

  • 0

My query is throwing an error like

select id,cHospital from med_patient where cHospital is not null  union
select id,cHospital1 from med_patient where cHospital1 is not null  union
select id,cHospital2 from med_patient where cHospital2 is not null  order by 1

The error is

Notice: Undefined index: cHospital1 in F:\wamp\www\mmr-final\admin\all_hospital_list.php on line 97

Notice: Undefined index: cHospital2 in F:\wamp\www\mmr-final\admin\all_hospital_list.php on line 98

Notice: Undefined index: cHospital1 in F:\wamp\www\mmr-final\admin\all_hospital_list.php on line 97

Notice: Undefined index: cHospital2 in F:\wamp\www\mmr-final\admin\all_hospital_list.php on line 98

Notice: Undefined index: cHospital1 in F:\wamp\www\mmr-final\admin\all_hospital_list.php on line 97

Notice: Undefined index: cHospital2 in F:\wamp\www\mmr-final\admin\all_hospital_list.php on line 98

Notice: Undefined index: cHospital1 in F:\wamp\www\mmr-final\admin\all_hospital_list.php on line 97

Notice: Undefined index: cHospital2 in F:\wamp\www\mmr-final\admin\all_hospital_list.php on line 98

Notice: Undefined index: cHospital1 in F:\wamp\www\mmr-final\admin\all_hospital_list.php on line 97

Notice: Undefined index: cHospital2 in F:\wamp\www\mmr-final\admin\all_hospital_list.php on line 98

Notice: Undefined index: cHospital1 in F:\wamp\www\mmr-final\admin\all_hospital_list.php on line 97

Notice: Undefined index: cHospital2 in F:\wamp\www\mmr-final\admin\all_hospital_list.php on line 98`

And also it’s throwing Null row.

How can this query be changed to not cause an error?

  • 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-13T11:16:26+00:00Added an answer on May 13, 2026 at 11:16 am

    In a UNION query, the column names must be the same for all rows. So it uses the column names from the first query in the union. Column names in subsequent queries in the union are ignored.

    In other words, in this query:

    select id,cHospital from med_patient where cHospital is not null union 
    select id,cHospital1 from med_patient where cHospital1 is not null union 
    select id,cHospital2 from med_patient where cHospital2 is not null order by 1
    

    The column names on all rows are: id and cHospital.

    So in your PHP code, when you fetch the result as an object and try to reference a field of the object like this:

    $cHospital1 = $row->cHospital1;
    $cHospital2 = $row->cHospital2;
    

    The object doesn’t have fields by those names. It only has $row->cHospital, even for rows that came from the second and third queries in the union.

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

Sidebar

Related Questions

the following query is not getting executed. it is throwing error. i am not
The following query used to work: select * from information_schema.columns where column_name like ...
im tearing my hair out over this one. A query is throwing an error:
Query's throwing an ORA-00907 Error when I try to paste a list of values
Query 1: SELECT * FROM user_d1 WHERE EXISTS (SELECT 1 FROM `user_d1` WHERE birthdate
Query: SELECT u.user_id,r.totalVotes votes,r.totalPoints rating,@row:=@row+1 rank FROM mismatch_user u LEFT JOIN ratingItems r ON
Query: SELECT DISTINCT ([Equipment List].ID) AS Expr1, [Job Assignments].Job FROM [Equipment List] LEFT JOIN
Query was this: CREATE TABLE `query` ( `id` int(11) NOT NULL auto_increment, `searchquery` varchar(255)
I'm doing a simple preparedstatement query execution and its throwing me this error: java.sql.SQLException:
I am making a search box feature that has this query: $query=SELECT * FROM

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.