Ask a Question related to Coldfusion Database Access, Design and Development.
-
drforbin1970 #1
HELP WITH GROUP BY
This should be easy but can't seem to figure it out today.
Have a table with three columns and corresponding data:
ID / prod_desc / flag_id
100 / JB / 0
100 / JB / 1
100 / JB / 2
101 / ME / 3
102 / QU / 4
I need the output to read:
100 / JB / <any JB record, can be 0, 1 or 2>
101 / ME / 3
102 / QU / 4
Can't GROUP BY because of flag_id column. Tried DISTINCT and self-join. Can't
figure out.
Help is appreciated, thanks in advance!
drforbin1970 Guest
-
"group by" - order of rows in group
this is simple example: TABLE SCHEMA: create table my_table( id int unsigned not null auto_increment primary key, project varchar(255) not... -
May 29 Sydney Developers Group study group
On Monday 29th May, we'll be studying Actionscript 3. Please read the articles prior to the meeting (see <a target=_blank... -
cfgrid inside a <cfoutput query="myQuery" group="GROUP">
Is it possible to use a cfgrid inside a cfoutput with a query and a group. When I try do that I get the following error: INVALID_CHARACTER_ERR:... -
group
I've made a group called everyone. It has its own Sub-directory, "/home/everyone". I have 3 users in the group. Do I have to do anything else so... -
Hi to the group
X-No-Archive: Yes Hi, Been lurking for the most part and I thought posting every now and then, but realized that I had been throwing those out... -
philh #2
Re: HELP WITH GROUP BY
Originally posted by: drforbin1970
I need the output to read:
100 / JB / <any JB record, can be 0, 1 or 2>
101 / ME / 3
102 / QU / 4
Do you need ONLY the ME/ 3 and QU/4 records?
SELECT TOP 1 * FROM Mytable WHERE prod_desc = 'JB'
UNION
SELECT * from Mytable where (Prod_desc = 'ME' and flag_id = 3) or (prod_desc
= 'QU' and flag_id = 4)
philh Guest
-
drforbin1970 #3
Re: HELP WITH GROUP BY
Those values are not known beforehand, need to group the data somehow.
drforbin1970 Guest
-
Dan Bracuk #4
Re: HELP WITH GROUP BY
If you don't need the flagid, don't select it. Also use the keyword distinct in your select clause. You won't have to group.
Dan Bracuk Guest
-
healey_mark #5
Re: HELP WITH GROUP BY
Alternatively, you could use MAX or MIN aggregate functions for this:
select MIN( ID ), prod_desc, MIN(flag_id)
from theTable
group by prod_desc
healey_mark Guest



Reply With Quote

