sql - Selecting Values based on value -


i have table 6 columns int values areaid forigen key.

    b1 h1 f1 a1 u1 areaid     0  3  -1 40 -1 120     34 7  -1 3  -1 120 

what need able select statement return distinct list of above columns areaid = 120 discount cols value of -1

so above example return ideally columns: b1, h1, a1,

can me this?

many thanks

jason

select distinct    nullif(b1, -1) b1,    nullif(h1, -1) h1,    nullif(f1, -1) f1,    nullif(a1, -1) a1,    nullif(u1, -1) u1    mytable    areaid = 120 

to discard -1 values, you'd have change them else. can't ignore columns in sql, mask them. in sql, -1 values ignored distinct.

so let's 1 of h1 rows had -1, still need include row not -1. this, you'd have in client. unless mean "ignore column -1 exists in of rows", not sql @ all. again, client side processing

tl:dr: sql not allow dynamic columns. unless want use dynamic sql

also see sql exclude column using select * [except columna] tablea? similar.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -