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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:01:22+00:00 2026-06-13T22:01:22+00:00

I have a table with a list of consignments for different users (table name

  • 0

I have a table with a list of consignments for different users (table name is consignments). This table contains the consignment id (cons_id) as PK, the user_id and the date (and other details).

I have another table which contains the details of these consignments (table name is consignment). It has item_id as PK, cons_id as FK, the weight, tracking numbers and other details of the consignment. There are more than one entry in this table with the same foreign key which relates to a single entry in the first table (consignments).

I want to select all the entries in the first table (consignments) for a specific user, together with details obtained from the 2nd table (i.e. the total weight of all the items for a specific consignment, which are entries in the 2nd table, etc.).

I use the following mysql command:

SELECT a.cons_id, a.user_id, a.date, 
       sum(c.weight) AS weight, sum(c.weight*2) AS amount, 
       count(c.tracking) AS qty 
FROM   `consignments` AS a LEFT JOIN `consignment` AS c 
       ON c.cons_id = a.cons_id WHERE a.user_id = 103

This returns only the first item in the consignments table for that specific user and not the remainder of the entries. Off course, if I do not join it with the 2nd table, all the entries are returned.

I am not sure whether the aggregates like sum is the problem and how to do it correctly.

Any suggestion would be highly 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-13T22:01:23+00:00Added an answer on June 13, 2026 at 10:01 pm

    Use group by:

    Example doing the weight (more sum() terms can be easily added):

    SELECT a.cons_id, a.user_id, a.date, sum(c.weight) AS weight
    FROM consignment a, consignments c where a.cons_id = c.cons_id 
    GROUP BY a.cons_id,a.user_id, a.date;
    

    Proof:

    create table consignment ( cons_id integer, user_id integer, date timestamp );
    create table consignments ( cons_id integer, item_id integer, weight integer );
    insert into consignment values ( 1, 1, now());
    insert into consignment values ( 2, 1, now());
    insert into consignments values ( 1, 1, 10);
    insert into consignments values ( 1, 2, 200);
    insert into consignments values ( 2, 1, 12);
    insert into consignments values ( 2, 2, 24);
    

    Run the above query

     cons_id | user_id |            date            | weight 
    ---------+---------+----------------------------+--------
           2 |       1 | 2012-11-05 23:20:34.158361 |     36
           1 |       1 | 2012-11-05 23:20:25.535398 |    210
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this table: SUBSCRIPTION NAME SUBSCRIBER It's essentially a table having a list
I have a table which contains a list of Surveys (PK is ID) CREATE
I have a table which contains a list of products for a company. They
I have a table that contains multiple dropdown menus for a list of profile
I have a table that contains a list of EquipmentIDs and another table that
I have a large table with list of scores like this, one score per
I have a table with a list of names. This table has an ID
I have a table with a list of businesses. Each row has details such
I have a table called Order_List that contains a list of orders. Each column
Let’s say I have table/list like this n=3 in this case, but n can

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.