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
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

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.