MySql : SELECT COLUMNS WHERE COLUMNS VALUE ARE SAME

孤人 提交于 2020-01-07 08:24:29

问题


This is my table data..

column_1_____column_3_____column_4_____column_5_____column_6_____column_7_____column_8 
   yes         no           yes           yes          yes          no           yes   

here, their is only one datarow

i want only that columns which has value = 'yes'.

for this which query works? Thanks.


回答1:


SQL is not organized around columns. It is organized around rows. You can do what you want with a query like this:

select 'column1' as col
from t
where column1 = 'yes'
union all
select 'column2' as col
from t
where column2 = 'yes'
union all
. . .
union all
select 'column8' as col
from t
where column8 = 'yes';



回答2:


Your idea isn't suitable for sql logic. Because you want to know something, before query hasn't work yet.



来源:https://stackoverflow.com/questions/18207490/mysql-select-columns-where-columns-value-are-same

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!