where-clause

SQL - improve NOT EXISTS query performance

夙愿已清 提交于 2020-01-01 01:53:06
问题 Is there a way I can improve this kind of SQL query performance: INSERT INTO ... WHERE NOT EXISTS(Validation...) The problem is when I have many data in my table (like million of rows), the execution of the WHERE NOT EXISTS clause if very slow. I have to do this verification because I can't insert duplicated data. I use SQLServer 2005 thx 回答1: Make sure you are searching on indexed columns, with no manipulation of the data within those columns (like substring etc.) 回答2: Off the top of my head

PL/SQL rewrite concatenated query with 'IN' clause

淺唱寂寞╮ 提交于 2019-12-31 04:08:09
问题 Currently I have in my pl/sql code following statements: -- vList looks like '1,2,3,4' vStatement := 'SELECT NAME FROM T_USER WHERE ID IN ( ' || vList || ' ) '; Execute Immediate vStatement BULK COLLECT INTO tNames; I think that concatenating of query if bad practice, so I want to make this query without using stings. What is the way to rewrite this ? P.S. maybe people here can point out why concatenation of queries is bad, because i don't have enough reasons to prove that this style is bad.

UPDATE Query without WHERE Clause

微笑、不失礼 提交于 2019-12-30 16:28:07
问题 I know it sounds to be a stupid question but i was wondering if the update query can be used without a where clause. And if so in what conditions. Thanks in advance. 回答1: if you don't use the WHERE clause all the records on the table will be affected 来源: https://stackoverflow.com/questions/12163047/update-query-without-where-clause

SQLite query where clause with floating point numbers fails?

喜欢而已 提交于 2019-12-30 10:02:38
问题 I'm putting a float in an Android based SQLite database, like so: private static final String DATABASE_CREATE = "create table " + DATABASE_TABLE + " (" + KEY_ID + " integer primary key autoincrement, " + KEY_FLOAT + " REAL, " + ... ... content.put(KEY_FLOAT, 37.3f); db.insert(DATABASE_TABLE, null, content); When I query the table: Cursor cursor = db.query(false, DATABASE_TABLE, new String[] { KEY_ID, KEY_FLOAT, ... }, KEY_LATITUDE + "=37.3", null, null, null, null, null); the cursor comes

LINQ is it possible to add where clauses dynamically

不打扰是莪最后的温柔 提交于 2019-12-30 06:18:25
问题 I want to search my db with different keys. According to the input, there may be 1 key to 10 keys. Is there a way to add OR/AND clauses to my Linq query dynamically? keys[k] // I have my keys in this array var feedList = (from feed in ctx.Feed where feed.content.contains(keys[0]) && feed.content.contains(keys[1]) && ... // continues with the keys.length select new { FeedId = feed.DuyuruId, FeedTitle = feed.FeedTitle, FeedContent = feed.FeedContents, FeedAuthor = user.UserName + " " +User

Correct indexing when using OR operator

[亡魂溺海] 提交于 2019-12-30 03:17:08
问题 I have a query like this: SELECT fields FROM table WHERE field1='something' OR field2='something' OR field3='something' OR field4='something' What would be the correct way to index such a table for this query? A query like this takes a entire second to run! I have 1 index with all 4 of those fields in it, so I'd think mysql would do something like this: Go through each row in the index thinking this: Is field1 something? How about field2? field3? field4? Ok, nope, go to the next row. 回答1: You

Dynamic where clause in Linq to Entities

一世执手 提交于 2019-12-30 03:15:24
问题 I'm using linq to entities(EF). I have a constructor which takes 4 string parameters. Depending on what parameter is not null I have to build the linq query. I can do with if else statements but i also has other constructor with 10 parameters in that case there will be many combinations to check. Example: Constructor(p1,p2,p3,p4) { var prod= from p in ctxt.products.expand("items\details") where p.x==p1 && p.xx==p2 && p.xxx==p3 && p.xxxx==p4 select p; } In the above where clause there should

mysql wildcards % vs %%

孤街浪徒 提交于 2019-12-29 07:53:12
问题 What is the difference in '%' and '%%', when used in mysql where clause with 'LIKE' ? select * from `wp_users` u where u.user_nicename like "%lastuser%" VS select * from `wp_users` u where u.user_nicename like "%%lastuser%%" 回答1: There is no difference between %% and % when it comes to pattern matching in mysql. I've seen developers get confused over this when they try to match a literal % and therefor write %% . This is most often because of the fact that format-strings often use a double %

How to use If Statement in Where Clause in SQL?

丶灬走出姿态 提交于 2019-12-29 06:42:09
问题 I need to use if statement inside where clause in sql. Select * from Customer WHERE (I.IsClose=@ISClose OR @ISClose is NULL) AND (C.FirstName like '%'+@ClientName+'%' or @ClientName is NULL ) AND if (@Value=2) begin (I.RecurringCharge=@Total or @Total is NULL ) end else if(@Value=3) begin (I.RecurringCharge like '%'+cast(@Total as varchar(50))+'%' or @Total is NULL ) end Note:This is not the complete code.Everything is defined in SP.I Just written the code that was needed to understand the

Why would a sql query have “where 1 = 1” [duplicate]

坚强是说给别人听的谎言 提交于 2019-12-28 15:36:55
问题 This question already has answers here : Closed 10 years ago . I was going through a few queries I am maintaining, and a programmer had put in the queries "where 1=1" to me that always seems to evaluate to true. Are there benefits to this? Duplicate: Why would someone use WHERE 1=1 AND in a SQL clause? That question isn't an answer to this question. Where-clause: select * from table where 1=1 and sStatus not in ('status1','status2','status3') No programming or if statements to push an and in