473,396 Members | 2,068 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,396 software developers and data experts.

Select groupping by one column

Hello list,

I have a table called pedh that looks like this:

REFNO FECHA OCNUM PVD
0199 10/12/2003 5224 632
0199 10/12/2003 5224 632
1264 10/18/2003 8991 210
1264 10/18/2003 8991 210
1264 10/18/2003 8991 210
9093 10/20/2003 6895 520
9093 10/20/2003 6895 520

I need to select one record groupped by column refno, I tried using this
code:

select refno, max(fecha), max(ocnum), max(pvd) from pedh

It seems to work fine, but is there another way to get the same result
avoing use of aggregate functions?
Thanks in advance


--
Josué Maldonado

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #1
2 1530
On Thu, Dec 18, 2003 at 15:09:52 -0800,
Josué Maldonado <jo***@lamundial.hn> wrote:
Hello list,

I have a table called pedh that looks like this:

REFNO FECHA OCNUM PVD
0199 10/12/2003 5224 632
0199 10/12/2003 5224 632
1264 10/18/2003 8991 210
1264 10/18/2003 8991 210
1264 10/18/2003 8991 210
9093 10/20/2003 6895 520
9093 10/20/2003 6895 520

I need to select one record groupped by column refno, I tried using this
code:

select refno, max(fecha), max(ocnum), max(pvd) from pedh
I don't see how that could work. Maybe you left off group by. But if you
did the aggreates could come from different rows, which might not be what
you want.

It seems to work fine, but is there another way to get the same result
avoing use of aggregate functions?


You might be able to use distinct on instead of aggregates.

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #2
Hello Bruno,

Bruno Wolff III wrote:

select refno, max(fecha), max(ocnum), max(pvd) from pedh

I don't see how that could work. Maybe you left off group by. But if you
did the aggreates could come from different rows, which might not be what
you want.


I missed the group by 1, I'm sorry.

It seems to work fine, but is there another way to get the same result
avoing use of aggregate functions?

You might be able to use distinct on instead of aggregates.


Thanks

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Luc | last post by:
I am using Visual Studio 2003 and am getting lousy performance after using a datatable select and then trying to assign a value to a column of the row that was found: DataTable dt = new...
18
by: war_wheelan | last post by:
I am very new to Transact-SQL programming and don't have a programming background and was hoping that someone could point me in the right direction. I have a SELECT statement SELECT FIXID,...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
10
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I...
33
by: Peter | last post by:
People are telling me it is bad to put select * from <atable> in a view. I better should list all fields of the table inside the definition of the view. I dont know exactly why but some...
0
by: ramesh | last post by:
Hi All, Can any one have any idea that how can I group items in a listview, somewhat like the XP style groupping. But the condition is that it should works in win98 too. I am using .NET 1.1 fro...
48
by: Jimmy | last post by:
thanks to everyone that helped, unfortunately the code samples people gave me don't work. here is what i have so far: <% Dim oConn, oRS, randNum Randomize() randNum = (CInt(1000 * Rnd) + 1) *...
1
by: RichardR | last post by:
I have a webpage which has a table that contains a column with several drop down boxes (<SELECT>). The contents of the drop down boxes are dynamically populated so I have no idea what the actually...
2
by: djnokturnal | last post by:
Hey guys / gals, First time posting and of course I am sure it is something that has been answered 100 times but for some reason I just cant find the answer :) First off here is the structure...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.