Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-06-2004, 09:40 PM
|
#1
|
Member
Registered: Mar 2004
Location: manila, philippines
Distribution: RH 7.3
Posts: 63
Rep:
|
SQL query help pls.
good day to all.
i have this sql query and return a result upto 10,000 records.
Code:
SELECT cocv.personality_id, province_code, municipality_code, votes, personalities.personality_nam_last, personalities.personality_nam_first,
certificates_candidacy.position_id, position_prov_ipd_id, position_munc_ipd_id, leg_dist_ipd_id
FROM (cocv INNER JOIN personalities
ON cocv.personality_id = personalities.personality_id) INNER JOIN certificates_candidacy
ON cocv.personality_id = certificates_candidacy.personality_id
WHERE certificates_candidacy.position_id = '30';
but when i add a GROUP BY function
it gives me different numbers of results. how is that happened?
|
|
|
10-06-2004, 11:56 PM
|
#2
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
Where are you adding the grouping?
Cheers,
Tink
|
|
|
10-07-2004, 05:58 AM
|
#3
|
Member
Registered: Mar 2004
Location: manila, philippines
Distribution: RH 7.3
Posts: 63
Original Poster
Rep:
|
Quote:
Originally posted by Tinkster
Where are you adding the grouping?
Cheers,
Tink
|
i add the grouping at the last of the sql
Code:
SELECT cocv.personality_id, province_code, municipality_code, votes, personalities.personality_nam_last, personalities.personality_nam_first,
certificates_candidacy.position_id, position_prov_ipd_id, position_munc_ipd_id, leg_dist_ipd_id
FROM (cocv INNER JOIN personalities
ON cocv.personality_id = personalities.personality_id) INNER JOIN certificates_candidacy
ON cocv.personality_id = certificates_candidacy.personality_id
WHERE certificates_candidacy.position_id = '30'
GROUP BY certificates_candidacy.leg_dist_ipd_id, cocv.personality_id, province_code, municipality_code, votes, personalities.personality_nam_last, personalities.personality_nam_first,
certificates_candidacy.position_id, position_prov_ipd_id, position_munc_ipd_id;
|
|
|
10-08-2004, 04:44 PM
|
#4
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
I don't understand what your problem is - maybe you
mistook "group by" for "order by"? Group by, by definition,
will collapse multiple entries for one of the criteria into
a single hit ... the more group-by you do, the less results
you will get.
Cheers,
Tink
|
|
|
10-14-2004, 12:13 PM
|
#5
|
LQ Newbie
Registered: Oct 2004
Location: Fort Wayne IN
Distribution: Fedora, 2000pro, server
Posts: 26
Rep:
|
That is one long join statement do you really want all of that in a table whew.
Try at the end ORDER BY certificates_candidacy.leg_dist_ipd_id. just one category
Or order by just one category
What is happening is that it will order by the first one, then the second, then the third
and so on so you are really getting the same date multiple times just in different groups and orders
|
|
|
10-18-2004, 05:20 AM
|
#6
|
Member
Registered: Mar 2004
Location: manila, philippines
Distribution: RH 7.3
Posts: 63
Original Poster
Rep:
|
Quote:
Originally posted by Tinkster
I don't understand what your problem is - maybe you
mistook "group by" for "order by"? Group by, by definition,
will collapse multiple entries for one of the criteria into
a single hit ... the more group-by you do, the less results
you will get.
Cheers,
Tink
|
Thanks Tinkster..
You really give em a shagg!! i mistook those group by the order by..
More power!!
|
|
|
10-18-2004, 08:23 AM
|
#7
|
LQ Newbie
Registered: Oct 2004
Location: Fort Wayne IN
Distribution: Fedora, 2000pro, server
Posts: 26
Rep:
|
It is more proper procedure to group by only one category if you want to limit the
hit result you should do this in your select statement.
|
|
|
10-18-2004, 08:51 PM
|
#8
|
Member
Registered: Mar 2004
Location: manila, philippines
Distribution: RH 7.3
Posts: 63
Original Poster
Rep:
|
Quote:
Originally posted by Thomasseafort
It is more proper procedure to group by only one category if you want to limit the
hit result you should do this in your select statement.
|
Thanks for all of your help folks.
In my previous post i just want to use order by on my SELECT query rather than group by..
More Power!!
|
|
|
10-18-2004, 11:25 PM
|
#9
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
You're very welcome :)
Cheers,
Tink
|
|
|
All times are GMT -5. The time now is 01:13 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|