where-clause

Linq To Sql 'Where Or' operator

岁酱吖の 提交于 2019-12-18 12:28:51
问题 I need to create a query which checks if a field (string) contains one or more words supplied at run time. Basically I need to be able to ask a WhereOr question. This seems like it should be a common issue when dealing with LinqToSql. I found the following reference but can't make sense out of it - and have no idea how to use it in my project. i've tried the following loop: var query = from d in context.Domains select d; for (int i = 0; i < words.Length; i++) { query = query.Where(d => d.Name

SQL WHERE IN (…) sort by order of the list?

谁说我不能喝 提交于 2019-12-18 08:47:11
问题 Let's say I have query a database with a where clause WHERE _id IN (5,6,424,2) Is there any way for the returned cursor to be sorted in the order that the _id's where listed in the list? _id attribute from first to last in Cursor to be 5, 6, 424, 2? This happens to be on Android through a ContentProvider, but that's probably not relevant. 回答1: Select ID list using subquery and join with it: select t1.* from t1 inner join ( select 1 as id, 1 as num union all select 5, 2 union all select 3, 3 )

Order by Maximum condition match

你。 提交于 2019-12-18 05:56:37
问题 Please help me to create a select query which contains 10 'where' clause and the order should be like that: the results should be displayed in order of most keywords(where conditions) matched down to least matched. NOTE: all 10 condition are with "OR". Please help me to create this query. i am using ms-sql server 2005 Like: Select * from employee where empid in (1,2,4,332,434) or empname like 'raj%' or city = 'jodhpur' or salary >5000 In above query all those record which matches maximum

LIKE and NULL in WHERE clause in SQL

时光怂恿深爱的人放手 提交于 2019-12-18 05:42:48
问题 I have a store procedure which i have planned to use for search and get all values. Scenario: If the parameter passed is NULL it should return all the values of the table and if the parameter passed is not NULL it should return the values according to the condition which is in LIKE. //Query: ALTER procedure [dbo].[usp_GetAllCustomerDetails] ( @Keyword nvarchar(20) = null ) As Begin Select CustomerId,CustomerName,CustomerTypeName,CustomerCode,CategoryName,CustomerMobile,CustomerEmail

MySQL user-defined variable in WHERE clause

烈酒焚心 提交于 2019-12-18 05:36:32
问题 I want to know if there is a way to use a user-defined variable in WHERE clause, as in this example: SELECT id, location, @id := 10 FROM songs WHERE id = @id This query runs with no errors but doesn't work as expected. 回答1: Not far from what Mike E. proposed, but one statement: SELECT id, location FROM songs, ( SELECT @id := 10 ) AS var WHERE id = @id; I used similar queries to emulate window functions in MySQL. E.g. Row sampling - just an example of using variables in the same statement 回答2:

T-SQL Conditional WHERE Clause

给你一囗甜甜゛ 提交于 2019-12-17 23:42:40
问题 Found a couple of similar questions here on this, but couldn't figure out how to apply to my scenario. My function has a parameter called @IncludeBelow . Values are 0 or 1 (BIT). I have this query: SELECT p.* FROM Locations l INNER JOIN Posts p on l.LocationId = p.LocationId WHERE l.Condition1 = @Value1 AND l.SomeOtherCondition = @SomeOtherValue If @IncludeBelow is 0, i need the query to be this: SELECT p.* FROM Locations l INNER JOIN Posts p on l.LocationId = p.LocationId WHERE l.Condition1

MySQL Select: WHERE (time now) = BETWEEN tablevalue AND tablevalue

懵懂的女人 提交于 2019-12-17 20:45:35
问题 I'm looking for a way to select the row in which the current time is between two set values in the row. I've set up a table with 3 columns, 2 of them hold a timestamp (HH:MM:SS), the other one a string. Is there a way I can get the string corresponding to the current time? To put it in a more abstract way: SELECT String FROM TableName WHERE (Current Time) BETWEEN (Lower Limit Time Value) AND (Upper Limit Time Value); So basically, based on the current time, my script should output the correct

MySQL Select last 7 days

左心房为你撑大大i 提交于 2019-12-17 09:36:20
问题 I read some Posts here and seems like nothing special but I can not still select the entries of the last days. SELECT p1.kArtikel, p1.cName, p1.cKurzBeschreibung, p1.dLetzteAktualisierung, p1.dErstellt, p1.cSeo, p2.kartikelpict, p2.nNr, p2.cPfad FROM tartikel AS p1 WHERE DATE(dErstellt) > (NOW() - INTERVAL 7 DAY) INNER JOIN tartikelpict AS p2 ON (p1.kArtikel = p2.kArtikel) WHERE (p2.nNr = 1) ORDER BY p1.kArtikel DESC LIMIT 100;', $connection); If I add the between today and last 7 days my

Is a JOIN faster than a WHERE?

℡╲_俬逩灬. 提交于 2019-12-17 07:23:10
问题 Suppose I have two tables that are linked (one has a foreign key to the other) : CREATE TABLE Document ( Id INT PRIMARY KEY, Name VARCHAR 255 ) CREATE TABLE DocumentStats ( Id INT PRIMARY KEY, DocumentId INT, -- this is a foreign key to table Document NbViews INT ) I know, this is not the smartest way of doing things, but this is the best example I could come up with. Now, I want to get all documents that have more than 500 views. The two solutions that come to my mind are : SELECT * FROM

Does order of where clauses matter in SQL?

≯℡__Kan透↙ 提交于 2019-12-17 02:44:16
问题 Let's say I have a table called PEOPLE having 3 columns ID, LastName, FirstName , none of these columns are indexed. LastName is more unique, and FirstName is less unique. If I do 2 searches: select * from PEOPLE where FirstName="F" and LastName="L" select * from PEOPLE where LastName="L" and FirstName="F" My belief is the second one is faster because the more unique criterion ( LastName ) comes first in the where clause, and records will get eliminated more efficiently. I don't think the