Jump to content

Help With Selecting Values for Two Columns from Another Table


jackrabb1t

Recommended Posts

I need help to solve a problem I'm having in MySQL. I have two tables:

 

Table 1

id (primary key)

name

 

Table 2

id (primary key)

name1 (foreign id from table 1)

name2 (foreign id from table 2)

address

phone

 

What I need to do is select all the records in table 2, and order them by the first name from table 1 and then the second name from table 1. Obviously, sorting by the ID's won't work.

 

What is the best way to solve this problem?

  • 2 weeks later...

I'm working on a similar issue, and am trying to use a JOIN clause for my page.  Here's an example from W3Schools:

 

SELECT column_name(s)

FROM table_name1

JOIN table_name2

ON table_name1.column_name=table_name2.column_name

 

http://w3schools.com/sql/sql_join.asp

 

I'm having issues with getting my JOIN to work, but from what you've said, it looks like you might need to see about using that and then SORT by code to get what you want.  Sorry this wasn't much help - hope you're able to get it to work.

 

:)

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.