in-clause

Select Query by Pair of fields using an in clause

前提是你 提交于 2019-11-29 01:48:31
问题 I have a table called players as follows: First_Id Second_Id Name 1 1 Durant 2 1 Kobe 1 2 Lebron 2 2 Dwight 1 3 Dirk I wish to write a select statement on this table to retrieve all rows whose first ids and second ids match a bunch of specified first and second ids. So for example, I wish to select all rows whose first and second ids are as follows: (1,1), (1,2) and (1,3). This would retreive the following 3 rows: First_Id Second_Id Name 1 1 Durant 1 2 Lebron 1 3 Dirk Is it possible to write

SQL Server - IN clause with multiple fields

只愿长相守 提交于 2019-11-28 07:00:30
问题 Is it possible to include in a IN clause multiple fields? Something like the following: select * from user where code, userType in ( select code, userType from userType ) I'm using ms sql server 2008 I know this can be achieved with joins and exists, I just wanted to know if it could just be done with the IN clause. 回答1: Not the way you have posted. You can only return a single field or type for IN to work. From MSDN (IN): test_expression [ NOT ] IN ( subquery | expression [ ,...n ] )

Oracle: Dynamic query with IN clause using cursor

浪尽此生 提交于 2019-11-28 02:19:58
Could some one help me with creating a example, to implement a dynamic query that uses IN clause and populate the results to cursor. The input parameter could be array or string concatenated. I have been trying a lot but no successful. Thanks.. Clasic situation everyone has. You can form a Query string dynamically based on your array or sometthing. And use as OPEN CURSOR. . DECLARE v_mystring VARCHAR(50); v_my_ref_cursor sys_refcursor; in_string varchar2='''abc'',''bcd'''; id2 varchar2(10):='123'; myrecord tablename%rowtype; BEGIN v_mystring := 'SELECT a.*... from tablename a where name= :id2

Empty IN clause parameter list in MySQL

早过忘川 提交于 2019-11-27 20:58:40
What happens when you do a SQL query where the IN clause is empty? For example: SELECT user WHERE id IN (); Will MySQL handle this as expected (that is, always false), and if not, how can my application handle this case when building the IN clause dynamically? If I have an application where I'm building the IN list dynamically, and it might end up empty, what I sometimes do is initialize the list with an impossible value and add to that. E.g. if it's a list of usernames, I'll start with an empty string, since that's not a possible username. If it's an auto_increment ID, I'll use -1 because the

passing list to IN clause in HQL or SQL?

こ雲淡風輕ζ 提交于 2019-11-27 18:29:45
I get List<Strings> by executing a query. This must be passed to another query of IN clause values. How to pass them in HQL ? We can convert List to Array and can pass it, that's not a problem. Finally, I must pass the list in List<String> or Array or String form to the IN clause. from AUTOS a where a.model in (select m.model from MODELS m) or Query query1 = session.createQuery("select s.id from Salary s where s.salary < 50000 AND s.salary > 49980"); Query query2 = session.createQuery("from Employee e where e.id in (:ids)").setParameterList("ids", query1.list()); query2.list(); Sinan

Multiple Id's in In clause of SQL Query C# [closed]

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 09:54:34
I want to basically use multiple iD's in In clause of my sql query. Now i have two options one is to get the comma separated ID's from a textbox or i can put a list view or grid view to insert id's there and then get the id's to be used in sql statement. Can you please help me with the code, how to do this thing? In order to get textbox value you have to code like this:- "select * from table where id in ( "+textbox1.text+")"; But this will lead you to Sql Injection problem. So a better approach will be:- var command = new SqlCommand("SELECT * FROM table WHERE id = @value") { Connection =

SQL:Casting a String to IDS with IN clause

二次信任 提交于 2019-11-27 08:16:42
问题 DECLARE @STR_IDS VARCHAR(15) SET @STR_IDS='7,15,18' UPDATE TBL_USERS WHERE ID IN @STR_IDS I know the update statement would not work as the ID is of type INT and i am replacing a varachar value there .How can i change the query so that it will be executed like this in effect ? UPDATE TBL_USERS WHERE ID IN (7,15,18) Thanks in advace 回答1: Op doesn't mention database, so I'll just use SQL Server, because the example SQL in the question looks like TSQL. There are many ways to split string in SQL

How to pass a variable to a IN clause?

不打扰是莪最后的温柔 提交于 2019-11-27 08:14:45
Lets say I have a SP that has a SELECT statements as follows, SELECT product_id, product_price FROM product WHERE product_type IN ('AA','BB','CC'); But data goes to that IN clause must be through a single variable that contains the string of values. Something link below SELECT product_id, product_price FROM product WHERE product_type IN (input_variables); But its not working that way. Any idea how to do this? Pass parameter value like this - 'AA,BB,CC' . Then, it is enough to use FIND_IN_SET function - SELECT product_id, product_price FROM product WHERE FIND_IN_SET(product_type, param); create

Oracle: Dynamic query with IN clause using cursor

╄→гoц情女王★ 提交于 2019-11-27 04:53:27
问题 Could some one help me with creating a example, to implement a dynamic query that uses IN clause and populate the results to cursor. The input parameter could be array or string concatenated. I have been trying a lot but no successful. Thanks.. 回答1: Clasic situation everyone has. You can form a Query string dynamically based on your array or sometthing. And use as OPEN CURSOR. . DECLARE v_mystring VARCHAR(50); v_my_ref_cursor sys_refcursor; in_string varchar2='''abc'',''bcd'''; id2 varchar2

IN Clause with NULL or IS NULL

浪尽此生 提交于 2019-11-27 03:31:14
Postgres is the database Can I use a NULL value for a IN clause? example: SELECT * FROM tbl_name WHERE id_field IN ('value1', 'value2', 'value3', NULL) I want to limit to these four values. I have tried the above statement and it doesn't work, well it executes but doesn't add the records with NULL id_fields. I have also tried to add a OR condition but this just make the query run and run with no end in sight. SELECT * FROM tbl_name WHERE other_condition = bar AND another_condition = foo AND id_field IN ('value1', 'value2', 'value3') OR id_field IS NULL Any suggestions? Daniel A. White An in