Jump to content

Most Viewed Profile Page


mattyvx

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
Share on other sites

I just got it to work (i think) using:

SELECT table1.ID,table1.name, SUM(table2.Profile + table2.Website) as Hits FROM table1,table2 
WHERE table1.ID=table2.ID 
ORDER BY table2.Profile DESC Limit 0,5

 

Its probably not the most efficient way though...

Link to comment
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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.