Reputation: 25
I have tables like this
COUNT tbl id, userid, linkid, count
4
1
6
LINKS tbl
id, linkname, linkurl
What i want to do is to order the 'linkname' column in order of the count column and put it in an array. I am struggling becasue i am not understanding how to use JOIN.
I need to get linkid WHERE userid = $userid
Upvotes: 1
Views: 704
Reputation: 24661
Try this:
$userid = intval( $userid ); // Hopefully it's already an integer,
// but protect yourself from SQL Injection
SELECT linkname, C.count FROM Links INNER JOIN `Count` C ON C.linkid = Links.id
WHERE userid = $userid
ORDER BY C.count ASC
Upvotes: 1
Reputation: 2246
Try this: SELECT * FROM Links L JOIN Count C ON L.id = C.linkid
then you should have a count column.
Also, I recommend you don't use "count" as the name of a table since it is a SQL reserved word.
Upvotes: 0