Jump to content

Alphabetically sort an associative database?


K_N

Recommended Posts

I've got two seperate tables set up, one containing information about an item, e.g. titles, description, stats. The other just containing 3 fields, an entry id, an item id, and the id of a register user that has added that item. I want to be able to pull a user's entries like I am currently doing with:

SELECT * FROM `list` WHERE userid = '" .$id. "' ORDER BY id DESC

, but sort it by the titles in the information database alphabetically.

You can use a JOIN to 'join' the two tables. I had to guess some of the table names/columns, but you should be able to work it out:

 

select i.id
     , i.title
     , i.description
     , p.entry_id
from items i
join possessions p on (i.id = p.item_id)
where p.user_id = {$id}

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.