Jump to content

[SOLVED] Sort Table 1 by data in Table 2.


Recommended Posts

Ok I have 2 tables.

 

Table1          Table 2

 

ID                ID

Name            T1ID

                    Age

 

I'm wanting to sort the data in Table 1 by the Age column in Table 2 and then display NAME as it appears in order of AGE.

 

In this case ID on table 1 is the same and T1ID on table 2.

 

Is there a way to do this?

Link to comment
https://forums.phpfreaks.com/topic/85584-solved-sort-table-1-by-data-in-table-2/
Share on other sites

SELECT

            t1.Name

          , t2.Age

  FROM

            Table1 t1

    JOIN

            Table2 t2

      ON

            t2.T1ID = t1.ID

 

ORDER BY

            t2.Age ASC  # or use DESC for descending

;

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.