Jump to content

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


phpmo

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

;

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.