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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:11:13+00:00 2026-06-06T11:11:13+00:00

I’m having some trouble with finalizing my MySQL query. Imagine that i combine the

  • 0

I’m having some trouble with finalizing my MySQL query. Imagine that i combine the tables tickets, invoice line and users. Each ticket has one or more invoice lines and each user can have one or more tickets.

I’m trying to create a query which I can use to create the name badges. For this badge I need to know the name and the items the person registered for.

I created the following MySQL query

SELECT u.firstName, u.lastName, il.invID, il.name, 
CASE 
  WHEN il.name = 'Conference Dinner' 
  THEN 'Diner'
END AS 'conference_dinner',

CASE 
  WHEN il.name = 'Regular Conference Fee' THEN 'Conference'
  WHEN il.name = 'Conference Fee for Phd. Students'  THEN 'Conference'
END AS 'conference',

CASE
  WHEN il.name = 'Pre-Conference Fee' THEN 'Pre-Conference'
END AS 'pre_conference',

FROM invoice_line il, events_tickets et, users u
WHERE il.invID = et.invID
AND et.userID = u.ID

The query is almost fine, however it produces for a user with three invoice lines (= three items) three lines in the table, and I’d like these three lines to merge to one line. A Group By on the users ID will result in one line, but than the case created columns won’t be merged into the one line, only one of them is displayed.

I might have used the wrong way of doing this. But It should result in an table like this:

firstName | lastName | conference_diner | conference | pre_conference |
----------------------------------------------------------------------
John      | Doe      | Diner            | Conference |                |
Jane      | Norman   |                  | Conference | Pre-Conference | 
Martijn   | Thomas   |                  | Conference |                |
Pete      | Johns    |                  |            | Pre-Conference |

Currently this results in:

firstName | lastName | conference_diner | conference | pre_conference |
----------------------------------------------------------------------
John      | Doe      | Diner            |            |                |
John      | Doe      |                  | Conference |                |
Jane      | Norman   |                  | Conference |                |
Jane      | Norman   |                  |            | Pre-Conference |  
Martijn   | Thomas   |                  | Conference |                |
Pete      | Johns    |                  |            | Pre-Conference |

Thanks in advance

  • 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-06T11:11:15+00:00Added an answer on June 6, 2026 at 11:11 am

    You might try something along these lines:

    SELECT u.firstName, u.lastName, il.invID, il.name,
    IF(SUM(il.name = 'Conference Dinner') > 0,
        'Diner', '') AS 'conference_dinner',
    IF(SUM(il.name IN ('Regular Conference Fee',
                       'Conference Fee for Phd. Students')) > 0,
        'Conference', '') AS 'conference',
    IF(SUM(il.name = 'Pre-Conference Fee') > 0,
        'Pre-Conference', '') AS 'pre_conference'
    FROM invoice_line il, events_tickets et, users u
    WHERE il.invID = et.invID
    AND et.userID = u.ID
    GROUP BY u.ID
    

    A comparison in mysql results in a number, 0 for false and 1 for true. So you can simply sum those up to count the lines matching a given expression. In other words, all the lines from the join which belong to a single user are grouped, those matching a certain property are counted, and these counts will decide what to print as the aggregate value for that user in the resulting table.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.