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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:51:27+00:00 2026-06-18T06:51:27+00:00

I’m having some difficulty getting to the bottom of this sql query. Tables: –Tickets–

  • 0

I’m having some difficulty getting to the bottom of this sql query.

Tables:

--Tickets--         --Finance--          --Access--
id_tickets          id_finance           id_access
name_tickets        id_event             id_event
cat_tickets         id_tickets           id_tickets
                    sold_finance         scan_access

Finance and Access both contain a row for multiple of each ticket type as listed in tickets.
and I’m trying to get:

cat_tickets | total_sold | total_scan
-------------------------------------
single      | 3043       | 2571
season      | 481        | 292
comp        | 114        | 75
-------------------------------------
total       | 3638       | 2938

The closest I’ve been to the result I’ve used:

SELECT tickets.cat_tickets, COALESCE(SUM(finance.sold_finance), 0) AS total_sold, COALESCE(SUM(access.scan_access), 0) AS total_scan
FROM finance INNER JOIN tickets ON finance.id_tickets = tickets.id_tickets
INNER JOIN access ON access.id_tickets = tickets.id_tickets
WHERE access.id_event = 235 AND finance.id_event = access.id_event
GROUP BY tickets.cat_tickets
ORDER BY tickets.cat_tickets DESC

but that just returns:

cat_tickets | total_sold | total_scan
-------------------------------------
single      | 4945       | 4437
season      | 954        | 599
comp        | 342        | 375
-------------------------------------
total       | 6241       | 5411

Any ideas where I could be going wrong?
Thanks!

  • 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-18T06:51:28+00:00Added an answer on June 18, 2026 at 6:51 am

    The problem is the relation between access and finance tables, you have to join them. Even if you LEFT JOIN the table the predicate finance.id_event = access.id_event will make it INNER JOIN. As a work around, use UNION like this:

    SELECT 
      tickets.cat_tickets, 
      SUM(CASE WHEN a.Type = 'f' THEN num ELSE 0 END) AS total_sold,
      SUM(CASE WHEN a.Type = 'a' THEN num ELSE 0 END) AS total_scan
    FROM tickets 
    LEFT JOIN
    ( 
      SELECT 'f' Type, id_tickets, sold_finance num
      FROM finance f
      WHERE id_event = 1
      UNION ALL
      SELECT 'a', id_tickets, scan_access
      FROM access 
      WHERE id_event = 1
    ) a ON a.id_tickets = tickets.id_tickets
    GROUP BY tickets.cat_tickets;
    

    SQL Fiddle Demo

    • 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
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms

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.