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

  • Home
  • SEARCH
  • 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 131289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:04:55+00:00 2026-05-11T06:04:55+00:00

Consider following schema: Customers: Col | Type | ——————-| id | INTEGER | name

  • 0

Consider following schema:

 Customers: Col      | Type    | -------------------| id       | INTEGER | name     | VARCHAR |  Orders: Col         | Type    | ----------------------| id          | INTEGER | customer_id | INTEGER | date        | DATE    |  Items Col         | Type    | ----------------------| id          | INTEGER | order_id    | INTEGER | name        | VARCHAR | quantity    | INTEGER | 

And here’s the breif run down of the schema: Customer can have many orders, and an order can have many items Note: You may argue that the items should refer to some products table with a product_id, but let it be simple as is now.

From my database, I want to ask following question:

For a given customer, list all the items that start with La.

My version of the query goes like this:

SELECT * FROM items WHERE name LIKE ‘La%’

This would return ALL the items that Begin with La for ALL the customers. What I want is that I get all the items for a SPECIFIC customer with say id 1. How do I write such a query? My second version that would do is like this:

SELECT * FROM items WHERE name LIKE ‘La%’ AND order_id in (SELECT id FROM orders WHERE customer_id=1);

But is their any other efficient/elegant or a more better way to do the same thing?

  • 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. 2026-05-11T06:04:55+00:00Added an answer on May 11, 2026 at 6:04 am

    The elegant way to do this is called a join.

    SELECT   c.id            customer_id,   c.name          customer_name,   i.id            item_id,   i.name          item_name,   COUNT(i.id)     order_count,   SUM(i.quantity) items_ordered FROM   customers c   INNER JOIN orders o ON c.id = o.customer_id   INNER JOIN items  i ON i.id = o.order_id WHERE   i.name LIKE 'La%'   AND c.id = 1 GROUP BY   c.id,   c.name,   i.id,   i.name 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If they are truly unused stored procedures then there won't… May 12, 2026 at 5:23 pm
  • Editorial Team
    Editorial Team added an answer I used this regx in C#, and it works. Thanks… May 12, 2026 at 5:23 pm
  • Editorial Team
    Editorial Team added an answer java.util.Properties props = new java.util.Properties(); props.setProperty("password","mypassword"); props.setProperty("user","myusername"); props.put("v$session.osuser", System.getProperty("user.name").toString()); props.put("v$session.machine",… May 12, 2026 at 5:23 pm

Related Questions

Consider following schema: Customers: Col | Type | -------------------| id | INTEGER | name
Consider the following database schema: create table UserGroup ( id int not null auto_increment,
This might be a entity framework related question, anyway, here goes: Consider the following
Consider the following 2 tables: Table A: id event_time Table B id start_time end_time
Consider the following table with a constraint that's a bit daft but simple enough

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.