What I want to do it pull up the websites from table1 and order them based on the number of rows in table2 where `table1`.id = `table2`.site
you cannot order something by the number of rows... what you might be trying to do is having all of the similar sites together? and then list order then according to site id? or something like that? if that is correct, you can use this query
Code:
SELECT t1.id, t1.url, t2.id AS something_id, t2.site, t2.ip, t2.date FROM Table1 AS t1 LEFT JOIN Table2 AS t2 ON t2.site=t1.id GROUP BY t2.site ORDER BY t1.id ASC
Note that I changed the t2.id to something_id because you already have a field recording the id from Table1
The above statement will put all of the same site ids together so you would end up with something that could resemble
Code:
Table2:
id | site | ip | date
1 | 1 |127.0.0.1|2008-08-11
3 | 1 |127.0.0.1|2008-08-11
5 | 1 |127.0.0.1|2008-08-11
6 | 3 |127.0.0.1|2008-08-11
2 | 2 |127.0.0.1|2008-08-11
4 | 2 |127.0.0.1|2008-08-11
then to sort them a certain way we use the following statement
which will sort the results by the site id that you have specified in the first table, and I am sorting them in ascending (ASC) order, but you can also sort in descending (DESC) order which would look like
so our final results would look something like
Code:
Table2:
id|url |something_id | site | ip | date
1 |www.site1.com|1 | 1 |127.0.0.1|2008-08-11
1 |www.site1.com|3 | 1 |127.0.0.1|2008-08-11
1 |www.site1.com|5 | 1 |127.0.0.1|2008-08-11
2 |www.site2.com|4 | 2 |127.0.0.1|2008-08-11
2 |www.site2.com|2 | 2 |127.0.0.1|2008-08-11
3 |www.site3.com|6 | 3 |127.0.0.1|2008-08-11
if tat is not what you want, then can you possibly try to explain again what you are looking for
Bookmarks