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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:42:38+00:00 2026-05-28T02:42:38+00:00

I habe a main table that i select from and a table with subelements

  • 0

I habe a main table that i select from and a table with subelements that i select from in a join. Example:

person         skill           person_to_skill
id  | name     id | skill      id | p_id | s_id
------------   ------------    ----------------
1   | jim      1  | sewing     1  | 1    | 2
2   | peter    2  | cooking    2  | 2    | 1
3   | susan    3  | singing    3  | 2    | 3
4   | kevin                    4  | 3    | 1
                               5  | 3    | 2
                               6  | 4    | 3

So now we see, sim has only one skill, peter has two and so forth.
Now if i select from person, koin skill and then also join person_to_skill, but i only want two persons. How do i manage to do so without grouping and thereby not getting all the skills?

Shortly: I want to select two persons from “person” with all their skills.

I tried just using LIMIT but that limits the result rows, not the persons.
If i use GROUP BY i only get one skill per person.
Is this possible without a subselect?

Any ideas anyone?

My Approach so far, changed to work with the example, looks like this:

SELECT p.id,p.name,s.skill
FROM person AS p
LEFT JOIN person_to_skill psk ON (psk.p_id = p.id)
LEFT JOIN skill s ON (s.id = psk.s_id)
ORDER BY p.name
LIMIT 0,2
  • 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-28T02:42:38+00:00Added an answer on May 28, 2026 at 2:42 am

    Limit number of persons at very beginning in subquery then join to them other tables as you’ve already done:

    SELECT p.id,p.name,s.skill
    FROM (select * from person ORDER BY name LIMIT 0,2) AS p
    LEFT JOIN person_to_skill psk ON (psk.p_id = p.id)
    LEFT JOIN skill s ON (s.id = psk.s_id)
    

    Added after comment:

    If you really can’t use subqueries you can do it using two queries. Firstly select users ids:

    select id from person ORDER BY name LIMIT 0,2
    

    and then use those ids in next query:

    SELECT p.id,p.name,s.skill
    FROM person p
    LEFT JOIN person_to_skill psk ON (psk.p_id = p.id)
    LEFT JOIN skill s ON (s.id = psk.s_id)
    WHERE p.id IN (ids from previous query)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my application geting Text from a input field an post it over ajax to
My aim is to habe a listing of all wave files in a specific
I was playing fallout 3 and in that game the computer temrinals ha nice
i habe many entries in excell ( more than 3000 ). actually their are
I habe a problem with my latest Liferay Portlet or rather a JSP I'm
I habe a few million objects hanging around in memory. I want to find
I habe read here about defining method for a Javascript class Advantages of using
I have installed the Checkstyle plugin for Eclipse. When i habe writen now a
I create a number of add-ins for the Revit Structure API. Each tool has
I have my App published as a free and pro version to the android

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.