Skip to content
TechTeam.us

TechTeam.us

TechTeam computer repair, system management and web development

Menu

  • TechTeam.us Home
    • Computer Repair
  • TechTeam.us Blog
  • Useful Links
  • Contact Us

Uncategorized

Receiving the correct number of rows with an inner join

Daniel Uncategorized May 22, 2016

To receive the correct number of rows with an inner join we can use LIMIT and OFFSET on a sub-query.

SELECT id,field1,field2,field3,field4,field5 FROM (SELECT id,field1,field2,field3 FROM mytable ORDER BY id LIMIT 0,10) mytabled INNER JOIN myjointable USING (id);

Select the first row of each group in MYSQL

Daniel Uncategorized May 22, 2016May 22, 2016

This solution depends on having a unique column you can order by. In the example it is “id”. You must have a unique column to use for ordering or else you could get more than one result per group.

SELECT m.* FROM mytable AS m JOIN (SELECT category, MIN(id) AS id FROM mytable GROUP BY category) AS t USING (id);

Recent Posts

  • Classic British Phrases
  • Receiving the correct number of rows with an inner join
  • Select the first row of each group in MYSQL
  • Famous Five ’78/’79 Filming Locations
  • Alfresco Browser SSL Certificate

Recent Comments

    Archives

    • May 2018
    • May 2016
    • March 2016
    • August 2015
    • April 2015
    • February 2015
    • November 2014
    • August 2014

    Categories

    • Computing
    • Linux
    • MySQL
    • Odd Stuff
    • Programming
    • Uncategorized
    • Windows

    Meta

    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org
    Copyright © 2025 TechTeam.us. All rights reserved.
    Theme: Accelerate by ThemeGrill. Powered by WordPress.