Jump to content

Recommended Posts

SQL Server version: 5.0.85

 

Table 1 : ID,Name,*..other fields which are not applicable*

Table 2 : ID,Profile,Website

_______________________________________________

 

Hi,

 

See above info for my setup. Table 1 stores member information. Table 2 stores how many times a users profile and website have been visited via my website (integers).

 

What i want to do is select a list of the top 5 viewed members - by top viewed i mean : (Profile visits + Website visits)

 

Any suggestions would be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/187142-most-viewed-profile-page/
Share on other sites

I doubt that that is the true solution all you are doing is sorting by profile + your query is the same as mine except you use sum and order by another field. Try:

 

SELECT t1.Name, sum(t2.Profile + t2.Website) as total
FROM table2 AS t2
JOIN table1 AS t1 USING (ID)
ORDER BY total DESC
LIMIT 5

It seems neither method works :S

 

Using

SELECT t1.name, sum(t2.Profile + t2.Website) as total
FROM table2 AS t2
JOIN table1 AS t1 USING (ID)
ORDER BY total DESC
LIMIT 5

 

For example if i have two members

           

Table 1

---------

ID  Name

1  John

2  Ian

---------

 

Table 2

---------

ID |  Profile  | Website

1        12          1

2          2            9

 

What im getting as a result is:

Ian (24 visits)

 

So its summing all the values and associating them with on ID...

 

Any idea?

 

What I want is

 

John (13)

Ian  (11)

 

(sorted by "total")

 

Thanks

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.