Jump to content

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.

 

:)

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.