in-clause

Postgres ORDER BY values in IN list using Rails Active Record

橙三吉。 提交于 2019-12-22 12:19:15
问题 I receive a list of UserIds(about 1000 at a time) sorted by 'Income'. I have User records in "my system's database" but the 'Income' column is not there. I want to retrieve the Users from "my system's database" in the Sorted Order as received in the list. I tried doing the following using Active Record expecting that the records would be retrieved in the same order as in the Sorted List but it does not work. //PSEUDO CODE User.all(:conditions => {:id => [SORTED LIST]}) I found an answer to a

MySQL Unexpected Results: “IN”-clause (number, 'string') on a varchar column

送分小仙女□ 提交于 2019-12-20 06:26:29
问题 In MySQL, why does the following query return '----' , '0' , '000' , 'AK3462' , 'AL11111' , 'C131521' , 'TEST' , etc.? select varCharColumn from myTable where varCharColumn in (-1, ''); I get none of these results when I do: select varCharColumn from myTable where varCharColumn in (-1); select varCharColumn from myTable where varCharColumn in (''); Note: I'm using MySQL version 5.0.45-log ( show variables like "%version%"; ) Note 2: I tried this on a number column as well, but I do not get

Empty IN clause parameter list in MySQL

梦想与她 提交于 2019-12-17 10:56:15
问题 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? 回答1: 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

MySQL number of items within “in clause”

天涯浪子 提交于 2019-12-17 00:59:55
问题 I have three tables to define users: USER: user_id (int), username (varchar) USER_METADATA_FIELD: user_metadata_field_id (int), field_name (varchar) USER_METADATA: user_metadata_field_id (int), user_id (int), field_value (varchar) I'd like to create a middle tier user that has certain access to other users within the application. To determine which users the logged in use can access, I am using a subquery like the following: SELECT user_id FROM user WHERE user_id IN (SELECT user_id FROM user

SQL queries inside IN() clause

≡放荡痞女 提交于 2019-12-13 19:19:47
问题 I have SELECT query based on IN() clause, where I want to feed that clause with other queries like: SELECT * FROM item_list WHERE itemNAME IN ( SELECT itemNAME FROM item_list WHERE itemID = '17' AND (itemSUB ='1' OR itemSUB ='0') ORDER BY itemSUB DESC LIMIT 1, SELECT itemNAME FROM item_list WHERE itemID = '57' AND (itemSUB ='0' OR itemSUB ='0') ORDER BY itemSUB DESC LIMIT 1 ) But it errors with: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL

Combine 'like' and 'in' in a SqlServer Reporting Services query?

时光怂恿深爱的人放手 提交于 2019-12-12 20:03:43
问题 The following doesn't work, but something like this is what I'm looking for. select * from Products where Description like (@SearchedDescription + %) SSRS uses the @ operator in-front of a parameter to simulate an 'in', and I'm not finding a way to match up a string to a list of strings. 回答1: There are a few options on how to use a LIKE operator with a parameter. OPTION 1 If you add the % to the parameter value, then you can customize how the LIKE filter will be processed. For instance, your

Stuck on fixing this query, mistakes in two commands that I wrote

爱⌒轻易说出口 提交于 2019-12-12 04:41:48
问题 EMPLOYEE (fname, minit, lname, ssn, birthdate, address, sex, salary, superssn, dno) KEY: ssn DEPARTMENT (dname, dnumber, mgrssn, mgrstartdate) KEY: dnumber. PROJECT (pname, pnumber, plocation, dnum) KEY: pnumber. WORKS_ON (essn, pno, hours) KEY: (essn, pno) DEPENDENT (essn, dependent-name, sex, bdate, relationship) KEY: (essn, dependent-name) So I'm just really confused by how do I add more materials to the select command, let's say add SSN I want to find the last name and first name of all

Making MySQL IN Clause Case Sensitive

本秂侑毒 提交于 2019-12-10 03:47:13
问题 Does anyone know how I can make an IN clause behave in a case sensitive manner? I have seen that COLLATE can be used with LIKE for string searching but I don't know if or how it can be used with IN. For example I want to do something like SELECT * FROM pages_table WHERE topic IN ('Food','NightLife','Drinks') And I want it to return pages where the topic is 'Food' but not those where the topic is 'food' which is currently what happens on this query. Thanks. 回答1: You can actually use it as you

SQL IN Clause - get back IN elements that did not match

会有一股神秘感。 提交于 2019-12-08 07:00:52
问题 I'd like to run an SQL query to determine the occupants of a number of rooms. I'd also like to see which rooms are empty. I can find the occupants using SQL of the form: SELECT Room, OccupantName FROM Rooms WHERE Rooms IN ("Room 1", "Room 2", "Room 3", "Room 4") However, if only Rooms 1 and 2 have occupants, eg Room OccupantName Room 1, Person A Room 2, Person B how can I get something of the form: Room OccupantName Room 1, Person A Room 2, Person B Room 3, Nobody Room 4, Nobody Is there a

Oracle “IN clause” from parameter

我的梦境 提交于 2019-12-07 13:00:01
问题 I'm very unfamiliar with Oracle and am just trying to get this to work. I've looked here and here but have no idea how to make it all work. Here's what I need. I need a proc that will accept a comma-delimited string as a parameter that I can use in the "IN clause" of the query and return a cursor result. Is ther a way to do this in one, all-inclusive proc? If not, what are the different steps I need to take? Again, I apologize for my lack of knowledge of Oracle, this is just trying to get