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
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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.