where-clause

ServiceStack ORMLite - How to Select All to match the request DTO's properties automatically

↘锁芯ラ 提交于 2019-12-11 13:54:35
问题 I have several ServiceStack ORMLite POCO, one is Company below. public class Company { [AutoIncrement] public int id { get; set; } public string company { get; set; } public int? companyNo { get; set; } public bool? active { get; set; } } If two properties are valid in the following request: req.company="ABC Company", req.active=ture, and all other properties are null. Then it can return all records matching the two properties. The code may look like below: public object Get(Company req) {

SQL, ignore where cause if PHP value is empty

﹥>﹥吖頭↗ 提交于 2019-12-11 10:58:57
问题 Does anyone know how to get a mysql query to ignore a certain where condition if the PHP value is empty. I am trying to create an advance search engine with many strict where conditions to filter search, but would like the SQL to ignore some of the where causes if the PHP value is empty. For example: $condition_1 = ' '; $condition_2 = 'Random'; mysql_query("SELECT something FROM table WHERE row_1='$condition_1' && row_2='$condition_2'") There will be 15 where causes in the query, so anything

Checking if a mysql row is NOT in an array

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 08:59:18
问题 I know that you can use WHERE `age` IN ($ages) to find rows where the column age equals a part of an array. But what i need to find out is - What if you want to find rows where age is NOT in the array?? thanks 回答1: You need NOT IN . Yep, it really is that simple. $ages = "1,3,4,7,9"; // Your SQL WHERE clause... WHERE `age` NOT IN ($ages) 来源: https://stackoverflow.com/questions/6873734/checking-if-a-mysql-row-is-not-in-an-array

Single filter not working when where clause have specified value [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-12-11 08:25:03
问题 This question already has answers here : How to join two tables with ssp.class.php (3 answers) Closed 2 years ago . I set my datatable only show data which start with OQC . require('ssp.class.join.php' ); $joinQuery = "FROM `monitor` AS `a` JOIN `sym_category` AS `b` JOIN `model_cat` AS `c`"; $joinQuery.= "ON (`b`.`id_sym` = `a`.`id_sym`) AND (`c`.`id_mod` = `a`.`id_mod`)"; $joinQuery.= " WHERE `a`.`id_car` LIKE 'OQC%'"; echo json_encode( SSP::simple( $_GET, $sql_details, $table, $primaryKey,

Logical Processing Order or SQL Standard in WHERE clause

六月ゝ 毕业季﹏ 提交于 2019-12-11 08:21:20
问题 I was asked couple days ago about logical processing order of the SELECT statement and more specifically about aliases and where clause and I'm not sure about one issue. If we have a query like: SELECT name AS first_name FROM people WHERE first_name = 'Alan'; The reason why usage of aliases in WHERE clause will generate error is really logical processing order of the SELECT statement, or rather syntax parsing issue, or maybe is the rule from SQL standard? 回答1: It is the rule from the SQL

Case statement in where clause w/an OR

こ雲淡風輕ζ 提交于 2019-12-11 08:12:32
问题 Apologies in advance since I feel like I'm probably forgetting/missing something obvious on this one. Here goes; I'm using a case statement in my WHERE clause, the below works fine: WHERE r.[SomeCol] = @SomeColVal AND SomeOtherCol = ( CASE WHEN (@Year = 0 AND @Period = 0) THEN @SomeVal WHEN... ... ELSE @SomeVal END My "issue" is that I want to add an additional OR clause to my ELSE block..something like this: WHERE r.[SomeCol] = @SomeColVal AND SomeOtherCol = ( CASE WHEN (@Year = 0 AND

mysql udf json_extract in where clause - how to improve performance

拥有回忆 提交于 2019-12-11 07:17:44
问题 How can I efficiently search json data in a mysql database? I installed the extract_json udf from labs.mysql.com and played around with a test table with 2.750.000 entries. CREATE TABLE `testdb`.`JSON_TEST_TABLE` ( `AUTO_ID` INT UNSIGNED NOT NULL AUTO_INCREMENT, `OP_ID` INT NULL, `JSON` LONGTEXT NULL, PRIMARY KEY (`AUTO_ID`)) $$ An example JSON field would look like so: {"ts": "2014-10-30 15:08:56 (9400.223725848107) ", "operation": "1846922"} I found that putting json_extract into a select

Fetch record from 1st table which are not in 2nd table mysql

浪子不回头ぞ 提交于 2019-12-11 06:06:15
问题 I have following records in these two mysql tables. Table-A Question_No 1 2 3 4 5 Table-B Roll_No Question_No Ans_Option 1001 1 NULL 1001 2 D 1001 3 NULL 1002 1 C 1002 2 NULL Here the word "NULL" is explicitly inserted into column , nothing to be confused. How can I display the following result by mysql query? Questions not attempted by roll no 1001 are : 1, 3, 4, 5 Questions not attempted by roll no 1002 are : 2, 3, 4, 5 I tried with following code but not working select distinct a.* from

Is there a better way of writing this Linq Query

落爺英雄遲暮 提交于 2019-12-11 04:12:36
问题 Example from O in db.Orders join C in db.Customers on C.Id equals O.CustID Where O.ord_date == ( filter.OrderDate != null ? filter.OrderDate : o.ord_date) && c.Id == (filter.CustId != null ? filter.CustId : c.Id) && o.ProductId == ( filter.ProductId != null ? filter.ProductId : o.ProductID) select new {o,c} //select new {c.Name, C.JoinDate, O.Value, O.NoofLineItems } When i trun on the profile it has a lot of case statements as i expect it to have. but i have lot more control on the condition

zend framework where statement in query

守給你的承諾、 提交于 2019-12-11 04:08:51
问题 How can I use And/or in mysql queries using php and zend framework.for now I am using this : $db=Zend_Db_Table::getDefaultAdapter(); $select=new Zend_Db_Select($db); $select->from('users','*'); $select->joinInner('rest', 'users.repository = rest.id',array('username')); $select->where('username='.$rest.' and sold=0'); return $db->fetchAll($select); is that the correct way ? if not what is the correct way? 回答1: You can add AND 's to your query by calling where() multiple times: $select->where(