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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:52:14+00:00 2026-05-30T15:52:14+00:00

I have the following database tables: People +——–+————+————+———–+ | f_ID | F_NAME | STUFF

  • 0

I have the following database tables:

People
+--------+------------+------------+-----------+
|  f_ID  |  F_NAME    |    STUFF   | F_VALUE   | 
+--------+------------+------------+-----------+
|    1   |   Zoe      |    blah    |     101   |
|    2   |   Jimy     |    derka   |     202   |
|    3   |   Kate     |    shazam  |     20    |
|    4   |   Sue      |    pow     |      2    |
+--------+------------+------------+-----------+

RESULTS
+------- ---+------------+
| F_ID      |   RESULTS  | 
+-----------+------------+
| 1         |     Good   |
| 4         |      OK    |
+-----------+------------+

How do I create a query to display all entries in people table like this:

+------------+------------+
|   NAME     |    GRADE   | 
+------------+------------+
|   Zoe      |     Good   |
|   Jimy     |     N/A    |
|   Kate     |     N/A    |
|   Sue      |     OK     |
+------------+------------+

I tried this query but it doesn’t work correctly:

SELECT 
NAME
GRADE
(
SELECT 
p.F_NAME AS NAME,
r.RESULTS

FROM People p
JOIN RESULTS r ON r.F_ID=p.F_ID

UNION

SELECT 
p.F_NAME AS NAME,
"N/A"

FROM People p
JOIN RESULTS r ON r.F_ID=p.F_ID
)a
  • 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-30T15:52:15+00:00Added an answer on May 30, 2026 at 3:52 pm

    You should use left join. You will get NULL for GRADE where records don’t exist. When presenting the data, just put N/A instead of null.

    select People.F_NAME as NAME, RESULTS.RESULTS AS GRADE
    from People left join RESULTS ON People.f_ID = RESULTS.f_ID
    

    or, if you want N/A instead of null, use IF

    select People.F_NAME as NAME, IF(RESULTS.RESULTS is NULL, 'N/A', RESULTS.RESULTS) AS GRADE
    from People left join RESULTS ON People.f_ID = RESULTS.f_ID
    

    or using COALESCE (thanks @bfavaretto)

    select People.F_NAME as NAME, COALESCE(RESULTS.RESULTS, 'N/A') AS GRADE
    from People left join RESULTS ON People.f_ID = RESULTS.f_ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database schema that includes the following tables: People Organisations RelationshipTypes What
I have the following (simplified) database tables: Products - ProductID, int, PK - Name,
I have two database tables with the following structure: actions: action_id int(11) primary key
I have three mysql table from same database Db1. Three tables have following columns.
I have the following tables in my database: Products ID_PRODUCT PRODUCTNAME PRICE Customers ID_CUSTOMER
I have the following tables in a database (i'll only list the important attributes):
I have the following two tables in my mysql database. Table Name: groups id
I have the following tables, with these keys in my database: bookings session_id sessions
I have a database with two tables, tblPlayers and tblMatches. tblPlayers contains the following
I have a database with the following tables, Member, Paper, Topic, Interest, Associated. I

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.