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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:00:16+00:00 2026-05-29T06:00:16+00:00

This is for a homework assignment. I haven’t copy-pasted the question below, I made

  • 0

This is for a homework assignment. I haven’t copy-pasted the question below, I made an simpler version of it that focuses on the specific area where I’m stuck.

Let’s say I have a table of two values: a person’s name, and the place he had lunch yesterday. Assume everyone has lunch in pairs. How can I query the database to return all the pairs of people that had lunch together yesterday? Each pair must be only listed once.

I’m actually not even sure what the professor means by return them as pairs. I’ve sent him an email, but no reply yet. It seems like he wants me to write a query that returns a table with column 1 as person 1 and column 2 as person 2.

Any suggestions on how to go about this? Does it seem right to assume he wants them as separate columns?

So far, I basically have:

SELECT name, restaurant FROM lunches GROUP BY restaurant, name

which essentially just reorganizes the table so that the people who had lunch together are one after the other.

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

    We have to assume there can be only one pair eating lunch in a given restaurant.
    You can get a list of pairs either using self-join:

    SELECT l1.name, l2.name FROM lunches l1
    JOIN lunches l2
    ON l1.restaurant = l2.restaurant AND l1.name < l2.name
    

    or using GROUP BY:

    SELECT GROUP_CONCAT(name) FROM lunches 
    GROUP BY restaurant
    

    The first query will return pairs in two different columns, while the second in one column, using comma as separator (default for GROUP_CONCAT, you can change it to whatever you wish).
    Also note that for the first query names in pairs will come in alphabetical order as we use < instead of <> to avoid listing each pair twice.

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

Sidebar

Related Questions

Disclaimer: This is for a homework assignment, but the question is not regarding the
Disclaimer: this question is directly related to my programming homework. My C++ assignment consists
This is a homework assignment, just for all that want to know. I'm writing
I want to preface this by saying that this is a homework assignment. I
(this is indirectly a part of a much larger homework assignment) I have something
This is part of a homework assignment. I've got several questions asking find the
I'm doing a basic homework assignment which looks like this: While input <> -1
I know this sounds like a homework assignment, but it isn't. Lately I've been
Full disclosure : This is for a homework assignment. This is driving me nuts.
I'm working on this homework that's kind of confusing me... I am provided with

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.