where-in

Avoid SQL WHERE NOT IN Clause

放肆的年华 提交于 2019-12-19 10:27:51
问题 I have 3 tables listed below: Blog BlogArticle Article ---- ----------- ------- id id------blog_id -id title article_id__/ title This SQL describe what I want: SELECT * FROM `article` WHERE `article`.`id` NOT IN ( SELECT CONCAT(`blog_article`.`article_id`) FROM `blog_article` WHERE `blog_article`.`blog_id` = 1 -- example value ) The problem is, I have a big NOT IN values in that case, and as far as i know it will impact to server performance (I'm not sure since I've never try to benchmark or

Performing a WHERE - IN query in CouchDB

懵懂的女人 提交于 2019-12-18 22:39:07
问题 I would like to query for a list of particular documents with one call to CouchDB. With SQL I would do something like SELECT * FROM database.table WHERE database.table.id IN (2,4,56); What is a recipe for doing this in CouchDB by either _id or another field? 回答1: You need to use views keys query parameter to get records with keys in specified set. function(doc){ emit(doc.table.id, null); } And then GET /db/_design/ddoc_name/_view/by_table_id?keys=[2,4,56] To retrieve document content in same

NHibernate using QueryOver with WHERE IN

扶醉桌前 提交于 2019-12-18 10:27:39
问题 I would create a QueryOver like this SELECT * FROM Table WHERE Field IN (1,2,3,4,5) I've tried with Contains method but I've encountered the Exception "System.Exception: Unrecognised method call: System.String:Boolean Contains(System.String)" Here my code var qOver = _HibSession.QueryOver<MyModel>(() => baseModel) .JoinAlias(() => baseModel.Submodels, () => subModels) .Where(() => subModels.ID.Contains(IDsSubModels)) .List<MyModel>(); 回答1: I've found the solution!! :-) var qOver = _HibSession

MySQL specify arbitrary order by id

被刻印的时光 ゝ 提交于 2019-12-18 04:42:33
问题 Is it possible to specify an arbitrary order for a MySQL SELECT statement? E.g., SELECT * FROM table_name WHERE id IN (1, 3, 2, 9, 7) ORDER BY (1, 3, 2, 9, 7); The order of the numbers listed directly after IN do not seem to matter. 回答1: FIND_IN_SET function will do the trick SELECT * FROM table_name WHERE id IN (1, 3, 2, 9, 7) ORDER BY FIND_IN_SET(id, '1,3,2,9,7'); http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_find-in-set EDIT: Note the lack of spaces in the string

SQL use CASE statement in WHERE IN clause

限于喜欢 提交于 2019-12-18 03:05:26
问题 Is it posible to use case in where in clause? Something like this: DECLARE @Status VARCHAR(50); SET @Status='published'; SELECT * FROM Product P WHERE P.Status IN (CASE WHEN @Status='published' THEN (1,3) WHEN @Status='standby' THEN (2,5,9,6) WHEN @Status='deleted' THEN (4,5,8,10) ELSE (1,3) END) This code gives the error : Incorrect syntax near ','. 回答1: No you can't use case and in like this. But you can do SELECT * FROM Product P WHERE @Status='published' and P.Status IN (1,3) or @Status=

Passing multiple values for one SQL parameter

眉间皱痕 提交于 2019-12-17 19:30:48
问题 I have a CheckBoxList where users can select multiple items from the list. I then need to be able to pass these values to my Stored Procedure so they can be used in a WHERE condition like: WHERE ID IN (1,2,3) I tried doing this so that its a nvarchar parameter and i pass the string 1,2,3 with: WHERE ID IN (@IDs) But this returned the following error: Conversion failed when converting the nvarchar value '1,2,3' to data type int Any help would be much appreciated! 回答1: There's a few ways of

Force MySQL to return duplicates from WHERE IN clause without using JOIN/UNION?

拟墨画扇 提交于 2019-12-17 16:49:13
问题 This might not be very sensible, but I'ld like to let MySQL return me the exact duplicate rows if there are duplicate criteria in the WHERE IN clause. Is this possible? Take this example: SELECT columns FROM table WHERE id IN( 1, 2, 3, 4, 5, 1, 2, 5, 5) I'ld like MySQL to return me rows with id 5 three times, id's 1 and 2 twice, and 3 and 4 once. As the lenght of the IN arguments, as well as the duplicate count (once, twice, three times, etc.), will be arbitrary I don't want to rely on UNION

In MySQL how do I use a user defined variable in a WHERE IN clause?

房东的猫 提交于 2019-12-13 08:53:17
问题 I don't understand why this does not work. Can someone explain what I need to do? SET @my_list = '2,6,8,10,12,13,14,18,19,21'; DELETE FROM my_table WHERE my_table.table_id IN (@my_list); 回答1: It's interpreting @my_list as a single id and so you're asking it to delete from my_table where your id is the string "2,6,8,10,12,13,14,18,19,21" You could try SET @my_list = '2,6,8,10,12,13,14,18,19,21'; SET @exec = CONCAT('DELETE FROM my_table WHERE my_table.table_id IN (', @my_list ,')'); EXECUTE (

Do Oracle SQL DBs Remove duplicate entries in a where-in clause?

半腔热情 提交于 2019-12-12 03:52:04
问题 I apologize if this is a duplicate question: I've searched but finding many non-related topics/questions. For instance select * from table_of_things where id in (1, 2, 3, 4, 5, 6, 1, 2, 1) Will Oracle pre-processing remove the duplicates before performing the query? How can I find out? I imagine in large lists the performance loss can be huge and it would be good to remove duplicates myself before querying if not. 回答1: Like you, I couldn't find any specific documentation entry that specifies

MySQL where in executes slow if sub query is used, where as using list executes fast

久未见 提交于 2019-12-11 20:42:28
问题 the following executes fast: delete from text_blocks where text_id in ( 7684, 7683, 7682, ...); Note, the above list of values is short e.g. 130 retrieved from a separate query. Table text_blocks has ~ 7,000 rows. The following executes really slow: delete from text_blocks where text_id in (select a_text_id from someTable where name like "%_SomeSuffix"); The subquery in example 2 is the same as used to get the list of 130 in example 1. Neither text_id or a_text_id are indexed. Any ideas why