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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:45:15+00:00 2026-05-25T10:45:15+00:00

table1: id , otherColumn, otherColumn2 … table2: id, table1_id, someOtherColumns… I.E. one to many

  • 0

table1:

id , otherColumn, otherColumn2 ...

table2:

id, table1_id, someOtherColumns...

I.E. one to many relationships

A trivial join would be:

select * from table1 left outer join table2 on table2.table1_id=table1.id;

I want to do something different: for each row in table1, bring at most 1 row from table2, no matter which if there are several candidates. Just as I can limit the amount of results on a regular select

Is this possible? How?

  • 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-25T10:45:16+00:00Added an answer on May 25, 2026 at 10:45 am

    Possibilities:

    1. Use a sub-select. This will force the inner result-set to be limited. Advantage is that grouping/aggregation operations can be used. (I am not sure what issues, if any, MySQL has with sub-selects and holistic query planning.)

    2. Use a WHERE in the primary statement and let the SQL engine “do it’s thing”. If the WHERE can be “moved” before the join, a smart engine will do so as it will result in less rows being processed. I think this is part of the basic Relational Algebra model (for independent records), but I am not sure. Look at the query plan. (I do not use MySQL, so I do know what optimizations are done.)

    And, as always, verify results and run performance tests if it matters.

    Happy coding.

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

Sidebar

Related Questions

table1 (id, name) table2 (id, name) Query: SELECT name FROM table2 -- that are
I have a query with a sum in it like this: SELECT Table1.ID, SUM(Table2.[Number1]
I've saw a join just like this: Select <blablabla> from TableA TA Inner join
How would you reference table1 columns to 2 columns in table 2 I created
I have records in table1, if the records exist, it must copy into table2.
I have Table1 and Table2 related on Table1.ID. There can be zero or more
If I type: INSERT INTO table_b SELECT rowid, somecolumn FROM table_a ...the rowid column
I am trying to join two tables. One being the sys.databases table and the
I want to select a row (that appears multiple times) from a table ONLY
I have two tables table1 and table2. Table1 is generated by a parser and

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.