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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:21:09+00:00 2026-05-26T16:21:09+00:00

I have 4 tables: mysql> describe solution_sections; +———————+—————+——+—–+———+—————-+ | Field | Type | Null

  • 0

I have 4 tables:

mysql> describe solution_sections;
+---------------------+---------------+------+-----+---------+----------------+
| Field               | Type          | Null | Key | Default | Extra          |
+---------------------+---------------+------+-----+---------+----------------+
| solution_section_id | int(10)       | NO   | PRI | NULL    | auto_increment |
| display_order       | int(10)       | NO   |     | NULL    |                |
| section_name        | varchar(1000) | YES  |     | NULL    |                |
+---------------------+---------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> describe suggested_solution_comments;

+-----------------------+----------------+------+-----+---------+----------------+
| Field                 | Type           | Null | Key | Default | Extra          |
+-----------------------+----------------+------+-----+---------+----------------+
| comment_id            | int(10)        | NO   | PRI | NULL    | auto_increment |
| problem_id            | int(10)        | NO   |     | NULL    |                |
| suggested_solution_id | int(10)        | NO   |     | NULL    |                |
| commenter_id          | int(10)        | NO   |     | NULL    |                |
| comment               | varchar(10000) | YES  |     | NULL    |                |
| solution_part         | int(3)         | NO   |     | NULL    |                |
| date                  | date           | NO   |     | NULL    |                |
+-----------------------+----------------+------+-----+---------+----------------+


mysql> describe users;
+--------------+---------------+------+-----+---------+----------------+
| Field        | Type          | Null | Key | Default | Extra          |
+--------------+---------------+------+-----+---------+----------------+
| user_id      | int(10)       | NO   | PRI | NULL    | auto_increment |
| first_name   | varchar(100)  | NO   |     | NULL    |                |
| last_name    | varchar(100)  | NO   |     | NULL    |                |
| email        | varchar(150)  | NO   |     | NULL    |                |
| user_pass    | varchar(40)   | NO   |     | NULL    |                |
| zip          | varchar(100)  | NO   |     | NULL    |                |
| country      | varchar(100)  | NO   |     | NULL    |                |
| city         | varchar(100)  | NO   |     | NULL    |                |
| state        | varchar(100)  | NO   |     | NULL    |                |
| lat          | float(9,6)    | YES  |     | NULL    |                |
| lng          | float(9,6)    | YES  |     | NULL    |                |
| agreed_terms | tinyint(1)    | YES  |     | NULL    |                |
| join_date    | date          | NO   |     | NULL    |                |
| last_login   | date          | NO   |     | NULL    |                |
| bio_blurb    | varchar(5000) | YES  |     | NULL    |                |
+--------------+---------------+------+-----+---------+----------------+
15 rows in set (0.03 sec)

mysql> describe member_photo;
+-------------------+---------------+------+-----+---------+----------------+
| Field             | Type          | Null | Key | Default | Extra          |
+-------------------+---------------+------+-----+---------+----------------+
| photo_id          | int(10)       | NO   | PRI | NULL    | auto_increment |
| member_id         | int(10)       | NO   |     | NULL    |                |
| photo_description | varchar(3000) | YES  |     | NULL    |                |
| photo_path        | varchar(1000) | NO   |     | NULL    |                |
| small_thumb       | varchar(1000) | YES  |     | NULL    |                |
| mid_thumb         | varchar(1000) | YES  |     | NULL    |                |
| is_main_photo     | tinyint(1)    | YES  |     | NULL    |                |
+-------------------+---------------+------+-----+---------+----------------+

And I have a query like this:

select comment_id,
       commenter_id,
       section_name,
       comment,
       solution_part,
       display_order,
       solution_section_id,
       suggested_solution_id, 
       DAYOFMONTH(date),
       DAYNAME(date),
       YEAR(date),
       MONTH(date),
       first_name,
       last_name,
       email,
       small_thumb,
       mid_thumb 
from solution_sections 
left join suggested_solution_comments on
    solution_sections.solution_section_id = suggested_solution_comments.solution_part 
left join users on
    suggested_solution_comments.commenter_id = users.user_id  
left join member_photo on
    suggested_solution_comments.commenter_id = member_photo.member_id
where suggested_solution_id = 61 OR 
      suggested_solution_id IS NULL
order by solution_section_id,
         comment_id,
         section_name,
         comment,
         solution_part,
         display_order;

What its supposed to do is get each section_name from the solution_sections table, and then find the comments (and data about who commented). Sometimes there are no comments, but it should still return at least the row with section_name and all other things being null.

But for some reason it does not. And the weirdest part is that if I give it a different suggested_solution_id to match, it will return all of the rows of solution_sections.

Any ideas why such a thing might happen? Thank you!!

And I just realized one thing – if another comment has been made for any problem_id, this query won’t return the row with that section.

  • 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-26T16:21:10+00:00Added an answer on May 26, 2026 at 4:21 pm

    You need a left outer join to view all records from your parent table when child records are not guaranteed to exits. I’d also avoid adding a where clause when using outer joins.. I think its more readable to keep your join in a subselect, and filter the results.. Try something like this:

    select * from 
    (
        select sc.comment_id,
               sc.commenter_id,
               ss.section_name,
               sc.comment,
               sc.solution_part,
               ss.display_order,
               ss.solution_section_id,
               sc.suggested_solution_id, 
               DAYOFMONTH(sc.date),
               DAYNAME(sc.date),
               YEAR(sc.date),
               MONTH(sc.date),
               u.first_name,
               u.last_name,
               u.email,
               mp.small_thumb,
               mp.mid_thumb 
        from solution_sections ss
        left outer join suggested_solution_comments sc on ss.solution_section_id = sc.solution_part
        left outer join users u on sc.commenter_id = u.user_id  
        left outer join member_photo mp on sc.commenter_id = mp.member_id) a
    where a.suggested_solution_id = 61 OR 
          a.suggested_solution_id IS NULL
    order by a.solution_section_id,
             a.comment_id,
             a.section_name,
             a.comment,
             a.solution_part,
             a.display_order;
    

    EDIT:

    select sc.comment_id,
           sc.commenter_id,
           ss.section_name,
           sc.comment,
           sc.solution_part,
           ss.display_order,
           ss.solution_section_id,
           sc.suggested_solution_id, 
           DAYOFMONTH(sc.date),
           DAYNAME(sc.date),
           YEAR(sc.date),
           MONTH(sc.date),
           u.first_name,
           u.last_name,
           u.email,
           mp.small_thumb,
           mp.mid_thumb 
    from solution_sections ss
    left outer join suggested_solution_comments sc on ss.solution_section_id = sc.solution_part 
                                                   AND sc.suggested_solution_id = 61
    left outer join users u on sc.commenter_id = u.user_id  
    left outer join member_photo mp on sc.commenter_id = mp.member_id
    order by solution_section_id,
             comment_id,
             section_name,
             comment,
             solution_part,
             display_order;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 tables: mysql> describe solution_sections; +---------------------+---------------+------+-----+---------+----------------+ | Field | Type | Null
I have 2 tables: mysql> describe solution_sections; +---------------------+---------------+------+-----+---------+----------------+ | Field | Type | Null
I have the following 2 tables.. mysql> describe catalog_category_reference; +----------+---------+------+-----+---------+----------------+ | Field | Type
I have two associated tables (simplified schema) mysql> describe booking; +----------------+------------+ | Field |
so i have this table; mysql> describe player_weapon_stats; +------------+------------------+------+-----+---------+----------------+ | Field | Type |
I have 3 MySQL tables that describe a game: gamelist {gameId, ... with Primary(gameId)
Hi i ve got two tables like this: mysql> describe tb_data_iae; +--------------------+--------------+------+-----+---------+----------------+ | Field
--EDITED TO BETTER DESCRIBE THE SCENARIO-- I have a MySQL database containing 2 tables,
I have two mysql tables, one containing details on cars and one containing all
i have two mysql tables tableA colA1 colA2 1 whatever 2 whatever 3 whatever

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.