简体   繁体   中英

mysql avoid displaying results twice from 2 conditions

I have these 2 statements:

$pow= mysql_query("select options.label from options where userid='1'");

and:

$sql=("SELECT options.label from options WHERE userid=''");

$result= mysql_query($sql);

the first one would return the rows where the userid equals 1 and the second one where the are no user ids. the issue I am having is sometimes we have results with with the same label and userid=1 AND userid='' the labels are echoed on the page. I would like to return every label 1 time even if the row occurs twice. In other words I need the results that have userid=1 AND at the same time userid='' BUT if the field label is repeated, to show it only once.

为什么不使用distinct

select distinct options.label from options where userid='1'
select distinct(options.label) from options where userid='1' or userid=""

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM