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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:25:58+00:00 2026-05-23T06:25:58+00:00

I just started learning SQL a couple of days ago, and I’m trying to

  • 0

I just started learning SQL a couple of days ago, and I’m trying to understand which order I should use the SELECT statement when building subqueries. Here is a simple example of what I am trying to accomplish.

I have two tables – One that specifies the demographics of a customer list, and the other that details how they heard about our company.

In the first table, my customers are listed as either Male or Female in the Gender column, and then in the next column, their ethnicity is specified (Caucasian, African American, Hispanic, etc).

In the second table, there is a Referral column that specifies how they heard about our company (TV, radio, website, etc).

I want to first filter the customers by gender (I want to show only Female data), and then I want to count how many times our customers found us through our website for each ethnicity listed in the table.

SELECT Ethnicity, COUNT(Referral)
FROM Demographics, Marketing
WHERE Demographics.id = Marketing.source_id
AND Referral = 'website'
/* confused about how to put subquery here saying Gender = 'Female' */
ORDER BY Ethnicity

Basically, I’m confused about how to properly include the subquery and if I am even filtering in the correct order.

But here is what I want my table to look like:

/*Data is shown for ONLY Females */

Referral        Caucasian     African American       Hispanic      Asian

website          7             19                     14            22

I’m sorry, this code is probably really messed up. Please help if you can.

  • 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-23T06:25:59+00:00Added an answer on May 23, 2026 at 6:25 am

    From what you’ve described, you don’t need a subquery:

    SELECT Ethnicity, COUNT(Referral)
    FROM Demographics, Marketing
    WHERE Demographics.id = Marketing.source_id
    AND Referral = 'website'
    AND Gender = 'Female'
    ORDER BY Ethnicity
    

    …note that this gives you a different resultset from the one you’ve shown, though, with ethnicity, count on each row.

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

Sidebar

Related Questions

Just started learning NServiceBus and trying to understand the concept. When it talks about
I have just started learning Erlang and am trying out some Project Euler problems
I just started learning LINQ to SQL, and so far I'm impressed with the
I've just started learning how to use the Entity Framework to write a very
Just started learning to use the grid so please excuse me for the possibly
Just started learning how to use paper_clip. I installed everything according the instructions and
I just started learning Lisp and I don't seem to understand the following piece
I just started learning how to use SwiftMailer and I am having trouble sending
Hi Just started learning c for uni (usually use objective c) and have run
I'm a total newbie to programming and just started learning JAVA i order to

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.