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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:17:43+00:00 2026-05-14T04:17:43+00:00

I have this query: SELECT COUNT(articles.id) AS count FROM articles, xml_documents, streams WHERE articles.xml_document_id

  • 0

I have this query:

SELECT COUNT(articles.id) AS count 
FROM articles, xml_documents, streams 
WHERE articles.xml_document_id = xml_documents.id 
AND xml_documents.stream_id = streams.id
AND articles.published_at BETWEEN '2010-01-01' AND '2010-04-01'
AND streams.brand_id = 7

Which just uses the default equajoin by specifying three tables in csv format in the FROM clause.. What I need to do is group this by a value found within articles.source (raw xml).. so it could turn into this:

SELECT COUNT(articles.id) AS count, ExtractValue(articles.source, "/article/media_type") AS media_type
FROM articles, xml_documents, streams 
WHERE articles.xml_document_id = xml_documents.id 
AND xml_documents.stream_id = streams.id
AND articles.published_at BETWEEN '2010-01-01' AND '2010-04-01'
AND streams.brand_id = 7
GROUP BY media_type

which works fine, the problem is, I’m using rails, and using STI for the xml_documents table. The articles.source that is provided to the ExtractValue method will be of a couple different formats.. So what I need to be able to do is use “/article/media_type” IF xml_documents.type = ‘source one’ and use “/article/source” if xml_documents.type = ‘source two’

This is just because the two document types format their XML differently, but I don’t want to have to run multiple queries to retrieve this information..

It would be nice if one could use a ternary operator, but i don’t think this is possible..

EDIT
At this Point I am looking at making a temp table, or simply using UNION to place multiple result sets together..

  • 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-05-14T04:17:44+00:00Added an answer on May 14, 2026 at 4:17 am

    What about something like this:

    SELECT COUNT(articles.id) AS count,
           ExtractValue(articles.source,
               CASE xml_documents.type WHEN 'source one' then '/article/media_type'
                                       WHEN 'source two' then '/article/source'
                                       ELSE 'error'
               END),
    FROM ...
    

    EDIT
    Try this:

    SELECT COUNT(articles.id) AS count,
           CASE xml_documents.type WHEN 'source one' THEN ExtractValue(articles.source, '/article/media_type')
                                   WHEN 'source two' THEN ExtractValue(articles.source, '/article/source')
                                   ELSE NULL
           END as media_type,
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 383k
  • Answers 383k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use something like: import urllib2 import time import random MAX_WAIT… May 14, 2026 at 10:44 pm
  • Editorial Team
    Editorial Team added an answer You can make an array, use .push() to add items… May 14, 2026 at 10:44 pm
  • Editorial Team
    Editorial Team added an answer There are multiple solutions, it depends on what you want… May 14, 2026 at 10:44 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.