vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi, I'm using MySQL 5.0. I have the following result set ID VAL --- ------ 1 NULL 1 23.99 2 NULL 3 NULL 3 4.99 There will be at most 2 rows for a particular ID. But what I want is to select only one row for each ID and if given a choice, I want the row with a non-NULL VAL column. But if there is only one row for a particular ID, I want to select it. So from the above, I would want ID VAL --- ------ 1 23.99 2 NULL 3 4.99 Thanks for your help, - Dave |
| ||||
| On 8 Nov, 16:33, "laredotorn...@zipmail.com" <laredotorn...@zipmail.com> wrote: > Hi, > > I'm using MySQL 5.0. I have the following result set > > ID VAL > --- ------ > 1 NULL > 1 23.99 > 2 NULL > 3 NULL > 3 4.99 > > There will be at most 2 rows for a particular ID. But what I want is > to select only one row for each ID and if given a choice, I want the > row with a non-NULL VAL column. But if there is only one row for a > particular ID, I want to select it. So from the above, I would want > > ID VAL > --- ------ > 1 23.99 > 2 NULL > 3 4.99 > > Thanks for your help, - Dave Have a look for "strawberry query" in this NG. |