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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:16:51+00:00 2026-06-14T03:16:51+00:00

How can I group by in sql on a field from other table. Here’s

  • 0

How can I group by in sql on a field from other table. Here’s my code

select 
  sum(a.trans_amount), (
    select 
      ledger_name 
    from 
      ledger_master 
    where 
      ledger_master.ledger_code = transaction_ledger.ledger_code
  ) as ledger_name,
  ledger_code 
from 
  transaction_ledger 
where 
  ledger_parent = 'Sundry Debtors' 
group by 
  ledger_code,
  ledger_name
  • 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-14T03:16:52+00:00Added an answer on June 14, 2026 at 3:16 am

    Why not join the results and then grouping by?

    SELECT 
    SUM(Trans_Amount), 
    A.Ledger_Name, 
    A.Ledger_Code 
    FROM Transaction_Ledger A INNER JOIN Ledger_Master B 
    ON A.Ledger_Code=B.Ledger_Code 
    WHERE A.Ledger_Parent='Sundry Debtors' 
    GROUP BY A.Ledger_Code, A.Ledger_Name
    

    Your Ledger_Master and Transaction_Ledger has a related column “Ledger_Code” which you have used in the example query you have provided.

    Keeping that in mind, you can proceed to group by the required fields after a join on those two fields of the two tables.

    Luckily, the select list you want (Name & Code) can be used to group as well – thus not violating the grouping rules.

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

Sidebar

Related Questions

SQL query: select ApplicationNumber,pri_indicator,count(*) from customer group by ApplicationNumber,pri_indicator How do I do this
How can I using group by with union in T-SQL? I want to group
how can you do multiple group by's in linq to sql? Can you please
I have a SQL which can count the condition(Bad,Poor,Worse) in a day and group
i have some SQL code that is inserting values from another (non sql-based) system.
I am trying to update my table 1 with some field value from table
I have the following sql query: SELECT field_number, COUNT(*) AS c FROM lead_detail WHERE
I want to group the data from one of the tables in a SQL
I have a SQL table Values: id (int) | group (int) | value (int)
The sql query: select id,title from blog_post inner join (select object_pk, max(submit_date) from django_comments

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.