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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:03:16+00:00 2026-06-02T08:03:16+00:00

I have 2 tables: users & balance. I want to join the tables with

  • 0

I have 2 tables: users & balance.

I want to join the tables with all of the details from the user table (all fields of all tuples) with the most recent entry from the balance table (1 field linked by a user id).

Here is the structure of the tables:

balance:

+---------+
| Field   |
+---------+
| dbid    |
| userId  |
| date    |
| balance |
+---------+

users:

+-------------+
| Field       |
+-------------+
| dbid        |
| id          |
| fName       |
| sName       |
| schedName   |
| flexiLeave  |
| clockStatus |
+-------------+

I have been trying for hours to do this and the closest I can get is to return a row for a single user:

SELECT u.*, b.balance, b.date 
FROM users u, balance b 
WHERE
    u.id = b.userId AND
    b.date = (SELECT MAX(date) FROM balance WHERE userId = 'A8126982');

Or I can select all users but not the most recent entry in the balance table:

SELECT u.*, b.balance, b.date 
FROM users u, balance b 
WHERE u.id = b.userId GROUP BY u.id;

I have tried many different queries and seem to be getting closer but I just can’t get to where I want to be.

Any help would be 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-02T08:03:18+00:00Added an answer on June 2, 2026 at 8:03 am

    You can use the first SQL you wrote but for all users:

    SELECT u.*, b.balance, b.date
    FROM users u JOIN balance b ON u.id = b.userId
    WHERE b.date = (SELECT MAX(date) FROM balance WHERE userId = u.id);
    

    This may not be the fastest way to get the result, but it’ll give you what you need. I use similar queries in quite a few places in my app.

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

Sidebar

Related Questions

I have 2 tables: users & rent How to select name from table users
I have 4 tables... users, friends, articles & article_shares (as in written) A user
I have two tables User & User Log . User log table basically logs
I have two tables, users & projects users table: id username 1 sam 2
I want to join 4 tables which have group by , order by &
I have a database in which there is a user table & how many
I have two tables: Users: ID, first_name, last_name Networks: user_id, friend_id, status I want
I have 2 tables: users and subscribers . The relationship of the user to
I have 2 tables (Users, Wall). The UserID in the Wall table is a
I have two tables called lawyer & client.And they are the users of my

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.