Jump to content

MySql query - order by Count


mart94

Recommended Posts

Hi!

 

I created query:

$query = mysql_query("SELECT row, COUNT(*) AS rowCount FROM table1 WHERE row2 = 'something' GROUP BY row ORDER BY rowCount DESC");

What it does, it querys from database, and gives me something like TOP style, i mean, it Orders by rowCount, and it is working well, but now, i need little bit help, I want to take that Count from talbe2 also. And then Order by total count.

 

Hope you understand!

 

All The Best,

Mart

Link to comment
https://forums.phpfreaks.com/topic/216071-mysql-query-order-by-count/
Share on other sites

No, I don't.

 

I need query, witch counts from 2 different table "row" values, and orders by count total.

Example:

I have a table named T1, and it includes:

1 1

2 2

3 3

4 4

5 5

 

and another table named T2:

1 1

2 2

3 3

4 4

5 5

 

Now, query counts both values:

1 2

2 4

4 6

5 10

 

Now it orders it Desc

5 10

4 6

2 4

1 2

 

Table content can be also:

1 2

1 3

1 4

2 4

5 6

 

And second:

1 4

1 2

2 5

4 1

5 2

 

Counting result:

1 15

2 9

4 1

5 8

 

Ordering:

1 15

2 9

5 8

4 1

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.