473,378 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

mysql multi group by

Hello ,
I need a small help with multi GROUP BY .

Mysql example table with name 'mytable' has :

id - modelid - nameid
__________________________

1 | 1 | 2
2 | 5 | 6
3 | 3 | 11
4 | 2 | 10
5 | 6 | 1
6 | 7 | 1
7 | 5 | 1
8 | 8 | 1

I need to display number of count(modelid) and count(nameid) in one query . Is possible to do with GROUP BY. Please show me an query example with this resul:

modelid:5 count:2
modelid:1 count:1
modelid:3 count:1
modelid:2 count:1
modelid:6 count:1
modelid:7 count:1
modelid:8 count:1

nameid:1 count 4
nameid:2 count 1
nameid:6 count 1
nameid:11 count 1
nameid:10 count 1

Thank You!
Dec 27 '10 #1

✓ answered by Rabbit

You can't do this in one query. You can do it in two separate statements that you union together.

4 2527
Rabbit
12,516 Expert Mod 8TB
You can't do this in one query. You can do it in two separate statements that you union together.
Dec 27 '10 #2
Thank You for your reply Rabbit,

I'm afraid that I will lose performance because I need to search multi rows with MATCH AGAINST.

The goal is to extract result from database like newegg.com :P and I need to multi query MATCH AGAINST and GROUP BY .

Exist any other way with just mysql and php?

Thank You again!
Dec 27 '10 #3
Rabbit
12,516 Expert Mod 8TB
Match against doesn't require a group by nor a count so I don't know where you're going with this.
Dec 28 '10 #4
Yes I know ,

Just in my small project I need to group result like newegg do , with filter_items and count(filter_items).

My question was a simple table. In real database my query use match against and group by and for each type of filter_items is necessary to re-query the database.

My example was really stupid :P

To have an idea just search on newegg.com for "tv" and you will see on the left filter items : SubCategory, Useful Links, Price etc. with count for each one.

You have right , is not possible in one query.
Dec 28 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Westcoast Sheri | last post by:
To keep track of how many fruits my visitors buy, I use a mySQL database (2 columns: "fruit" and "quantity")....so can we make these following mySQL queries work somehow? (visitor buys 5...
0
by: Ganbold | last post by:
Hi, I'm new to multi-threaded programming and reading the book "Programming with POSIX Threads" and trying to understand concepts and coding. What I'm trying to do is to rewrite mysql client...
0
by: Gordon | last post by:
I have 2 tables t and t1. In this case, t1 is a copy of t. I want to delete rows from t1 based on criteria on the t table and a relationship between t ad t1 (in this case the id column). In the...
2
by: Sean Berry | last post by:
I have downloaded the source code for mysql-3.23.58. I unzip and untarred it and ran $ ./configure --prefix=/usr/local --localstatedir=/usr/local/mysql $ make $ make install $...
6
by: Ljoha | last post by:
I need to create report where will be shown total quantity of all rows for every hour in some data range. I have a table where I have column in DATETIME format. I have problem to create sql...
0
by: john.leonard.ireland | last post by:
Hi all, I don't know what I'm missing here, but if anyone could help me out I'd really appreciate it. Basically, everything is fine, compiles, installs, server runs, but the interactive mysql...
14
by: dottty | last post by:
Hi, i have a table that has the following fields: id, name, dept, pay 1, John, Sales, 4000 2, Peter, HR, 5000 etc. How do i count how many people there are in each dept with an sql query? ...
2
by: 2401 members, members can post | last post by:
Always MultiPost and Cross-Post messages to enhance the chance to reach you. Bob Hi, Ever be in a position of too-much traffic ?
2
by: Rink Web Site Developer | last post by:
Hello, I am currently having a bug with a MYSQL query for an online calendar I am writing. I have been looking at this bug for a couple days now and am still not able to figure out why it...
5
by: eko99312 | last post by:
Pardon me if this question already been asked before. I tried to sort a query to meet my desire. Here is the example: Date Customer Supplier Price 31-Oct-09 Charlie Australia $ 100...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.