简体   繁体   English

一列php mysql上的多个选择语句

[英]multiple select statement on one column php mysql

Hello i am trying to retrieve a list of records from my database and table using two criterias and the data has to be combined as one 您好,我正在尝试使用两个条件从我的数据库和表中检索记录列表,并且数据必须合并为一个

the first statement which i have written is 我写的第一句话是

FROM `transactions` WHERE `Start_Date` = '$_POST[start]' AND `Company` = '$_POST[star]' and Status = ''

this statement all the records which has its column as empty, 此语句将其列为空的所有记录,

now i want to also capture together with this data all columns that have status as successful 现在我还想与该数据一起捕获状态为成功的所有列

FROM `transactions` WHERE `Start_Date` = '$_POST[start]' AND `Company` = '$_POST[star]' and Status = 'successful'

please how do i combine this, i initially tried this 请我如何结合这个,我最初尝试过

FROM transactions WHERE Start_Date = '$_POST[start]' AND Company = '$_POST[star]' and Status = '' and (status = 'successful') FROM transactions Start_Date ='$ _POST [start]'AND Company ='$ _POST [star]'且Status =''和(status ='successful')

i thought it should work but it dosent seem to work, any help please on the correct way 我以为它应该工作,但似乎没什么用,请以正确的方式提供任何帮助

Each row in your table will be evaluated individually to see if it meets the criteria defined in the WHERE clause. 表中的每一行将分别进行评估,以查看其是否满足WHERE子句中定义的条件。 Since you need to check for two possible values in the same column, and one row cannot have two different values for the same column, you'll need to use OR instead of AND . 由于您需要检查同一列中两个可能的值,并且同一行中一行不能具有两个不同的值,因此您需要使用OR而不是AND

WHERE
    `Start_Date` = '$_POST[start]'
     AND `Company` = '$_POST[star]'
     AND (`Status` = '' OR `Status` = 'successful')

The effect of this will be like combining your two queries. 这样的效果就像合并两个查询。 You'll get all rows that meet the Start_date and Company criteria as well as having either Status = '' or Status = 'successful' . 你会得到满足的所有行Start_dateCompany标准以及具有或者 Status = '' Status = 'successful'

You can use "IN" operator to achieve this. 您可以使用“ IN”运算符来实现。

FROM 'transactions' WHERE 'Start_Date' = '$_POST[start]' AND 'Company' = '$_POST[star]' AND Status IN ('','successful') 在'事务'中,'开始日期'='$ _POST [开始]'和'公司'='$ _POST [星级]'AND状态为('','成功')

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

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