简体   繁体   English

mysql避免从2个条件中显示两次结果

[英]mysql avoid displaying results twice from 2 conditions

I have these 2 statements: 我有这两个陈述:

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

and: 和:

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

$result= mysql_query($sql); $ 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. 第一个将返回userid等于1的行,第二个返回没有用户id的行。 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. 我遇到的问题有时我们会得到具有相同标签和userid = 1 AND userid =''的结果,标签会在页面上回显。 I would like to return every label 1 time even if the row occurs twice. 我想将每个标签返回1次,即使该行出现两次。 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. 换句话说,我需要具有userid = 1 AND的结果同时userid =''但是如果重复字段标签,则只显示一次。

为什么不使用distinct

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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