Jump to content

Recommended Posts

Hi, Searched for ages and bit confused now lol so basically this is the situation. For my gaming website i got a roster/members list echoing out however i want to order it by rank so normally you'd use

 

$roster = mysql_query("SELECT * FROM roster WHERE gameplayed='Call of Duty 4' ORDER by rank");

 

however the roster table is like this

 

id            int

name          varchar

forumid              int

 

and well the player_profile page is well loads. but rank is varchar anyway and forumid is the primary field in player_profile

 

so basically yes, I need it to order it by rank, however the content of rank is stored within the player_profile table and not the roster.

 

is it possible for me to do this?

 

I saw something about forgien keys so dno if im misreading this which i think i am, but i thought

 

if i added a rank field into the roster table which was linked to hold the same content as rank in the player_profile field it would work? but i dno how to go about doing this :P i got phpmyadmin and navicat on the go but not really sure what I'm doing apart from that :)

 

THANKS

 

- Owen

 

 

Link to comment
https://forums.phpfreaks.com/topic/145087-order-by-different-table-s/
Share on other sites

Ah yes :P i discovered a useful feature in navicat that helps u build queries lol, and it seems that it came with the same answer as u did lol.

 

SELECT

*

FROM

roster

Inner Join player_profiles ON roster.id = player_profiles.rosterid

WHERE

roster.gameplayed =  'Call of Duty 4 Beta'

ORDER BY

player_profiles.rank ASC"

 

thats what it came up as, so basically didnt use the alias and used join inner rather than left.

 

what would the difference between Left and Inner achieve out of interest?

 

thanks for you help tho :) didnt expect that quick reply lol

A LEFT JOIN will pull rows despite whether information exists in the right table or not.  In other words, it will fill columns with NULL for rows that can't be found in the other table.

 

 

An INNER JOIN only pulls rows that have data in both tables.

 

 

http://www.tizag.com/mysqlTutorial/mysqlleftjoin.php

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.