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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:16:58+00:00 2026-06-18T07:16:58+00:00

Getting multiple records from table with subquery joins SELECT COUNT(*) AS total_count, (SELECT chat_box.user_id,

  • 0

Getting multiple records from table with subquery joins

SELECT
  COUNT(*) AS total_count,
  (SELECT
     chat_box.user_id,
     chat_box.message,
     members.id,
     members.display_name
   FROM chat_box INNER JOIN members
        ON chat_box.user_id = members.id
   ORDER BY chat_id DESC LIMIT 1),
  (SELECT COUNT(DISTINCT user_id) FROM chat_box) AS users_count
FROM chat_box

This is what I have so far, I want to get the members.display_name from the inner join where the chat_box.user_id = members.id as an output along aside the chat_box.message and save members.display_name and chat_box.message to a variable. Any help is appreciated.

  • 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-06-18T07:17:00+00:00Added an answer on June 18, 2026 at 7:17 am

    It is not exactly clear what you are trying to do, but it seems like you could use something like this:

    select u.user_id,
        u.message,
        u.id,
        u.display_name,
        cb1.total_count,
        cb1.users_count
    from
    (
        SELECT cb.user_id ,
            cb.message,
            m.id,
            m.display_name
        FROM chat_box cb
        INNER JOIN members m
            ON cb.user_id = m.id
    ) u
    CROSS JOIN
    (
        select COUNT(*) AS total_count,
              COUNT(DISTINCT user_id) AS users_count
        FROM chat_box
    ) cb1  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a lambda expression which can fetch multiple records from my table.
I previous recieved help with a problem, getting a multiple option select form to
SELECT * from `employees` a LEFT JOIN (SELECT phone1 p1, count(*) c, FROM `employees`
I have a table that has multiple records with a start date (PlacementDate) and
I have written a MySQL query (Ad rotate algorithm) to fetch records from multiple
I want to save my records from mysql table using PHP to an XML
I'm trying to create an html table from database records. I want the table
In $_SESSION['cart'] there are multiple records with table. But when I trying to send
I am issuing a query to elasticsearch and I am getting multiple record types.
I am having difficulty getting multiple jPicker instances of the same type to display

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.