Reputation: 1960
I'm asking this without code because I want to know a lot of ways of how to NOT return rows? What I'm now using is just not so neat. What i'm now using is '1=2' which allways returns in no rows.
So what i'm asking is a nice and neat way on how to NOT return rows in an sql statement.
UPDATE:
$sql = 'SELECT `a`.`id`,
`a`.`action_id`,
DATE_FORMAT(FROM_UNIXTIME(a.`time`), "%d-%m-%Y") as `date`,
DATE_FORMAT(FROM_UNIXTIME(a.`time`), "%H:%i") as `time`,
`a`.`amount_other_callers`,
`a`.`additional_data_incident`,
`a`.`additional_data_result`,
`a`.`additional_data_messagequality_start`,
`a`.`additional_data_messagequality_end`,
`a`.`additional_data_smsquality_start`,
`g`.`name` AS gemeente
FROM `actions` a
INNER JOIN actions_geo_communities AS ac
ON ac.lnk_action_id = a.id
INNER JOIN geodata_communities g
ON ac.lnk_community_id = g.id ';
if(Auth::user()->unit_id > 0) {
$sql.= ' INNER JOIN actions_geo_units AS au
ON au.lnk_action_id = a.id ';
}
if(Session::get('tk') === "1" && Session::get('ntk') === "1")
{
$sql.= ' WHERE `a`.`aangevuld` = 0 AND `a`.time > 1388530800';
}
else if (Session::get('tk') == 1)
{
$sql.= ' WHERE `a`.`aangevuld` = 0 AND `a`.`tk` = 1 AND `a`.time > 1388530800';
}
else if (Session::get('ntk') == 1)
{
$sql.= ' WHERE `a`.`aangevuld` = 0 AND `a`.`tk` = 0 AND `a`.time > 1388530800';
}
else
{
$sql.= ' WHERE 1=2';
}
if(Auth::user()->unit_id > 0) {
$sql.= ' AND `au`.`lnk_unit_id` = ' . Auth::user()->unit_id . ' ';
}
if(!empty($not_arr)) {
$sql.= ' AND `a`.`id` NOT IN (' . implode(',', $not_arr) . ') ';
}
Upvotes: 0
Views: 73
Reputation: 4385
Best answer for this is not run query , you didn't need any data so why you stress your database
In your case check if two or one check box is checked first then run your query otherwise don't run it at all
Upvotes: 3
Reputation: 1923
I've had this case when a module needed to augment the SQL that other modules have assembled. Based on what I knew in advance about the structure of incoming SQL-parts, I did one of these: when I just had a WHERE condition I transformed it to FALSE AND (<original_where)
or simply FALSE if it did not break the other modules. In other cases (when complex queries had multiple WHERE clauses and other clauses after WHERE) I had the luck that the system did not use LIMITs, so I was free to append LIMIT 0
Upvotes: 1