mysql sort by a column

hello,
I have a table that stores comment info for a message board.  The table has comment_body, id, and commenter_id in it.  there is another table with all the members that can post comments (member_id, member_name).  I want to be able to sort a question by the commenter name (not id).  I can't figure out how to sort the table alphabetically by info that is stored in another table.

if it is a complicated solution, I will raise the points.

Thanks!
LVL 6
mattjp88Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

inq123Commented:
Hi mattjp88,

You should be able to sort in sql, just "select comment_body, member_name from comment_table, member_table where member_table.member_id = comment_table.commenter_id order by member_name".

Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
suresh_aspCommented:
try this,

you can sort member_name as,

select comment_body, member_name from comment_table, member_table where member_table.member_id = comment_table.commenter_id order by member_name DESC;
0
inq123Commented:
I think most of time alphabetically means ascending order.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

EagleEye1975Commented:
You COULD read the entire array of comments in to an array, and while doing that, do lookups on the user names.

So it would be like...

while ($comment = mysql_fetch_row($comments))
{
   $username = mysql_fetch_row(mysql_query("select `Name` from `users` where `ID` = '$comment[2]' limit 1",$db))
   ...
}

Put all of the comment data in to a single line of information, seperated by something so you can explode it later.
Replace the IDs with the names, make the names the first items in the line, and do a sort() on the array...

It's a little more complicated than doing the ordering in the SQL statement as shown above, but it's another way to do it. :)
0
mattjp88Author Commented:
>inq123
Well, actually, I am going to be sorting alphabetically either A-Z or Z-A, whichever the user selects.  Thanks for the code!

>suresh_asp
the code is exactly like inq's, points them them.  Yours does work however.  thanks!

>EagleEye1975
Good alternate approach, although it isn't as efficient as doing it via the DB.

Thanks all!
0
preet_webspyCommented:
Please try this this may be helpful to you

Select c.comment_body, m.memeber_name from comment_table as c, member_table as m where c.comment_id=m.member_id order by m.member_name;

Keep the charcter fields in appropriate syntax.
This query is fast enough to get the desired resuts.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.