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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:25:48+00:00 2026-06-17T00:25:48+00:00

I have two tables, customers (with columns A , B ) and orders (with

  • 0

I have two tables, customers (with columns A, B) and orders (with columns C,D,A; the last one a foreign key).

This query returns the data I’m interested in:

SELECT customers.A, customers.B, orders.C, orders.D 
FROM customers, orders
WHERE customers.A = orders.A AND customers.B < 5 AND orders.D < 5

If I add LIMIT 10, I will get first ten 10 results (basically 10 orders), but what I want to do is to limit output based on the number of unique customers. So there would be exactly 10 unique customers in the result and therefore at least 10 – but likely more – orders. I think it’s possible to do that with a subquery but I can’t figure it out.

  • 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-17T00:25:49+00:00Added an answer on June 17, 2026 at 12:25 am

    Something like this:

    SELECT c.A, c.B, orders.C, orders.D 
    FROM (SELECT * FROM customers WHERE customers.B < 5 
          ORDER BY ....some-criteria... 
          LIMIT 10) c,
         orders
    WHERE c.A = orders.A AND orders.D < 5
    

    (Verified that sqlite successfully parses LIMIT in subqueries. Hopefully it doesn’t ignore this LIMIT silently).

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

Sidebar

Related Questions

I have two tables, one with products and a foreign key for the customer.
If I have two tables, Customers and Orders, and I want to look up
Let's say I have two tables one called Customers and one called CustomerAddresses. Then
I have the following two tables and data:- CREATE TABLE customers ([id] int, [name]
Using PHP / MySQL I have two tables one is customers the other is
I have two tables one named Person , which contains columns ID and Name
I have database with two tables: Customers (Id PK, LastName) and Orders (Id PK,
I have two tables: ZipCodes and customers. ZipCodes has columns for lng and lat
I have two tables, lets say table1 and table2 with common columns, id and
I have two tables one with ID and NAME table 1 ID | NAME

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.