On 8/10/15 3:42 PM, Eric Miller wrote:

I have a table that needs to be sorted alphabetically by names that aren't actually contained in the table *in sqlalchemy*. Only codes representing the names are in the table. Like so...


Table 1:

|row code month value 1 A 201501 50 2 Z 201501 100 3 CO 201501 200 4 VA 201502 300 5 C 201502 300 |


Table 2:

|row code name 1 A Apple 2 C Cascade 3 CO Colorado 4 VA Virginia |


I need to sort *Table 1* the following:

  * month
  * name (found in Table 2)

What is the best technique to achieve these sorting results when the sorting occurs on value not inherent in the table. I can't send the joined product of Table 1 and Table 2. Although, I can join them temporarily and remove the 'name' column if needed.


you need to produce rows that are a composite of table1 and table2, so that a single row contains both the columns you want to receive as well as the columns you intend to sort by. You do this using JOIN. SQL would be:

SELECT table1.* FROM table1 JOIN table2 ON table1.code=table2.code ORDER BY table2.name




--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com <mailto:sqlalchemy+unsubscr...@googlegroups.com>. To post to this group, send email to sqlalchemy@googlegroups.com <mailto:sqlalchemy@googlegroups.com>.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to