SQL First Match or just First -
because part of larger sql select statement, want wholly sql query selects first item matching criteria or, if no items match criteria, first item.
i.e. using linq want:
dim t1 = t in tt dim t2 = t in t1 criteria(t) dim firstifany = t in if(t2.any, t2, t1) take 1 select t
because if
not part of linq, linqpad doesn't show single sql statement, two, second depending upon whether criteria
matches of tt
values.
i know select top 1
etc. , can add order by
clauses specific first 1 want, i'm having trouble thinking of straightforward way first of 2 criteria. (it @ point when able solve myself.)
seeing don't see existing question this, let stand. i'm sure else see answer quickly.
select top 1 * ( select top 1 *, 1 rank mytable somecolumn = mycriteria union select top 1 *, 2 rank mytable order myordercolumn ) order rank
Comments
Post a Comment