get data from to tables !

Posted by mehdi on Stack Overflow See other posts from Stack Overflow or by mehdi
Published on 2010-04-11T11:26:34Z Indexed on 2010/04/11 11:33 UTC
Read the original article Hit count: 230

Filed under:
|

i want to sort my users based on most viewed profile in my user list . i have these two tables but i don't know how to right correct query to make this happen . i used grouping like this :

$sql ="select userid , count(*) form profile_visit group by userid " ; 

but it's not make sense to me , i don't think this query will help me at all .

+-----------+---------------+------+-----+-------------------+----------------+
| Field     | Type          | Null | Key | Default           | Extra          |
+-----------+---------------+------+-----+-------------------+----------------+
| userid    | int(11)       | NO   | PRI | NULL              | auto_increment |

| username  | varchar(128)  | NO   |     | NULL              |                |

| password  | char(40)      | NO   |     | NULL              |                |

| email     | varchar(128)  | NO   |     | NULL              |                |

| name      | varchar(256)  | NO   |     | NULL              |                |

| lastname  | varchar(256)  | NO   |     | NULL              |                |

| job       | varchar(256)  | NO   |     | NULL              |                |

| birthdate | varchar(100)  | NO   |     | NULL              |                |

| address   | varchar(1024) | NO   |     | NULL              |                |

| website   | varchar(100)  | NO   |     | NULL              |                |

| tel       | varchar(100)  | NO   |     | NULL              |                |

| role      | tinyint(1)    | NO   |     | 0                 |                |

| reg_date  | timestamp     | NO   |     | CURRENT_TIMESTAMP |                |

+-----------+---------------+------+-----+-------------------+----------------+

and profile_visit table like this

+------------+-------------+------+-----+---------+----------------+
| Field      | Type        | Null | Key | Default | Extra          |
+------------+-------------+------+-----+---------+----------------+
| id         | int(11)     | NO   | PRI | NULL    | auto_increment |
| ip_address | varchar(70) | NO   |     | NULL    |                |
| userid     | int(11)     | NO   |     | NULL    |                |
+------------+-------------+------+-----+---------+----------------+

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql