Created
July 28, 2008 08:57
-
-
Save jeffrafter/2864 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I want to JOIN only the last item | |
table_1 | |
------------ | |
id | Name | | |
============ | |
1 Bob | | |
============ | |
table_2 | |
--------------------------- | |
id | table_1_id | height | | |
=========================== | |
1 1 191 | | |
2 1 193 | | |
=========================== | |
SELECT * FROM table_1 | |
INNER JOIN table_2 ON table_1.id = table_2.table_1_id | |
Result: | |
================================= | |
1 Bob 1 1 191 | | |
1 Bob 2 1 193 | | |
================================= | |
What I want: | |
================================= | |
1 Bob 2 1 193 | | |
================================= | |
What I came up with: | |
SELECT * FROM table_1 | |
INNER JOIN (SELECT * from table_2 ORDER BY id DESC LIMIT 1) as table_2 ON table_1.id = table_2.table_1_id | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment