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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:28:22+00:00 2026-06-12T18:28:22+00:00

I have a simple table (ID, Member_ID, payment, date, payment_serial, running_total); I need the

  • 0

I have a simple table (ID, Member_ID, payment, date, payment_serial, running_total); I need the payment_serial to use the data for export to another system.

The export I need is all the payments made by a member (showing payment & date), sorted in order of the payment_serial and in a single row.

This was the first query I used:

SELECT
  `Member_ID`,
  IF(`payment_serial`=1,`payment`,0) AS `p1`,
  IF(`payment_serial`=1,`date`,0) AS `p1_date`,
  IF(`payment_serial`=1,`ID`,0) AS `p1_ID`,
  IF(`payment_serial`=2,`payment`,0) AS `p2`,
  IF(`payment_serial`=2,`date`,0) AS `p2_date`
  IF(`payment_serial`=2,`ID`,0) AS `p2_ID`,
FROM monthlies
WHERE `Member_ID` = 4198739

If I use this query, I see the payments I need, but each on a separate row (which creates big import problems at the next stage):

Member_ID    p1     p1_date  p1_ID    p2    p2_date  p2_ID ...
  4198739   34.50    41143    214      0      0       0    ... 
  4198739     0        0       0     34.50  41176    583   ...

I added GROUP BY:

SELECT
  IF(`payment_serial`=1,`payment`,0) AS `p1`,
  IF(`payment_serial`=1,`date`,0) AS `p1_date`,
  IF(`payment_serial`=1,`ID`,0) AS `p1_ID`,
  IF(`payment_serial`=2,`payment`,0) AS `p2`,
  IF(`payment_serial`=2,`date`,0) AS `p2_date`,
  IF(`payment_serial`=2,`ID`,0) AS `p2_ID`
FROM monthlies
WHERE `Member_ID` = 4198739
GROUP BY `Member_ID`

This gives me a single row for each member – but not each payment:

Member_ID    p1     p1_date  p1_ID    p2    p2_date  p2_ID ...
  4198739   34.50    41143    214      0      0       0    ... 

Where am I going wrong?

  • 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-12T18:28:23+00:00Added an answer on June 12, 2026 at 6:28 pm

    It’s not entirely your fault. MySQL implements GROUP BY wrong. Any other SQL platform would give you a syntax error at this point.

    Try

    SELECT 
      MAX(IF(`payment_serial`=1,`payment`,0)) AS `p1`, 
      MAX(IF(`payment_serial`=1,`date`,0)) AS `p1_date`, 
      MAX(IF(`payment_serial`=1,`ID`,0)) AS `p1_ID`, 
      MAX(IF(`payment_serial`=2,`payment`,0)) AS `p2`, 
      MAX(IF(`payment_serial`=2,`date`,0)) AS `p2_date`, 
      MAX(IF(`payment_serial`=2,`ID`,0)) AS `p2_ID` 
    FROM monthlies 
    WHERE `Member_ID` = 4198739 
    GROUP BY `Member_ID` 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple table view which is editable. All I need the user
I have simple table creating script in Postgres 9.1. I need it to create
I have a simple relation table of list_id and member_id +---------+--------+ |list_id | Member_id|
I have a very simple table called Member , which consists of the following:
I have simple table in Sybase -- Creating table 'SimpleText' CREATE TABLE [dbo].[SimpleText] (
I have a simple table that has this structure: <table> <thead> <tr> <td>Some info</td>
I have a simple table maintaining messages between users. The table structure looks like
I have a simple table like this <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
I have a simple table. The first column has max-width set at 15px. It
I have a simple table with autoincrementing ID's and one text column. id(int), value(nvarchar)

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.