[RESOLVED] [MySQL] Data from 2 tables ORDER BY issue
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: [RESOLVED] [MySQL] Data from 2 tables ORDER BY issue

  1. #1
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,881

    [RESOLVED] [MySQL] Data from 2 tables ORDER BY issue

    I want to get data from 2 tables...easy! Works as it should.

    Code:
    SELECT mam01_user.*, (SELECT nick FROM mam01_nicks WHERE user = mam01_user.id ORDER BY id DESC LIMIT 1) AS player FROM mam01_user, mam01_nicks LIMIT 10
    However, when I go to order it...I get 10 identical rows of information.

    Code:
    SELECT mam01_user.*, (SELECT nick FROM mam01_nicks WHERE user = mam01_user.id ORDER BY id DESC LIMIT 1) AS player FROM mam01_user, mam01_nicks ORDER BY mam01_user.lastseen DESC LIMIT 10
    What am I doing wrong?
    Last edited by PeejAvery; March 21st, 2014 at 12:28 PM.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,881

    Re: [RESOLVED] [MySQL] Data from 2 tables ORDER BY issue

    Nevermind. I ended up doing a LEFT JOIN instead.

    Code:
    SELECT * FROM mam01_user LEFT JOIN mam01_nicks ON mam01_user.id = mam01_nicks.user ORDER BY mam01_user.lastseen DESC LIMIT 10
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center