find-in-set

MySQL - delete where not in find_in_set

倾然丶 夕夏残阳落幕 提交于 2021-01-28 03:21:45
问题 I'm trying to find the right syntax to delete records that are not in a comma separated row. table A | id | product_id | attribute_id | |----|------------|--------------| | 1 | 123 | 45 | | 2 | 123 | 46 | | 3 | 124 | 34 | | 4 | 124 | 33 | table B | code | Axis | |------|-------| | 123 | 45,46 | | 124 | 34 | My goal is to remove all rows from table A where the attribute id is not in the table B axis value (in this example the row with id = 4). I try to do a SELECT before: SELECT A.attribute_id

MySQL - delete where not in find_in_set

左心房为你撑大大i 提交于 2021-01-28 02:08:37
问题 I'm trying to find the right syntax to delete records that are not in a comma separated row. table A | id | product_id | attribute_id | |----|------------|--------------| | 1 | 123 | 45 | | 2 | 123 | 46 | | 3 | 124 | 34 | | 4 | 124 | 33 | table B | code | Axis | |------|-------| | 123 | 45,46 | | 124 | 34 | My goal is to remove all rows from table A where the attribute id is not in the table B axis value (in this example the row with id = 4). I try to do a SELECT before: SELECT A.attribute_id

comma separated argument for IN operator, MySQL

别说谁变了你拦得住时间么 提交于 2020-06-23 07:43:11
问题 I have a table in which the following query works fine: select * from session_actions where action_type IN ('login_failed','channel_recorded') Now I'm looking forward to some thing like the following: select * from session_actions where action_type IN ('login_failed,channel_recorded') As you see I want to give the IN operator one single comma separated parameter, but it is not possible How can I convert this comma separated string into a list of parameters which is acceptable to IN operator?

Rails4 FIND_IN_SET with PG not working

醉酒当歌 提交于 2020-01-06 01:29:49
问题 Query select * from inboxes where find_in_set ('6',inboxes.to); Above query i am using for accessing record from my table 'inboxes' having one of the column 'to' values like (2,4,6,7) string separated by commas. I am using find_in_set function in pg but it shows me error with below hint. Hint: No function matches the given name and argument types. You might need to add explicit type casts. 回答1: You can simulate MySQL's find_in_set() function using an array in Postgres. select * from inboxes

How can I use FIND_IN_SET within a JOINED table?

时光毁灭记忆、已成空白 提交于 2019-12-31 07:01:51
问题 I have 2 tables: user : names of registered blood donors with their blood type. blood : contains blood types and blood compatibilities. e.g.: Blood id 5 (A-) can receive blood donations from 5 (A-) and 6 (O-). I have to build a search form that retreives potential blood donors. The form allows the user to search for specific blood type donors. If I search for blood type 5 (A-), the query should return all users that have 5 (A-) and 6 (O-) blood types, and the resulting list should display

How can I use FIND_IN_SET within a JOINED table?

假如想象 提交于 2019-12-31 07:01:16
问题 I have 2 tables: user : names of registered blood donors with their blood type. blood : contains blood types and blood compatibilities. e.g.: Blood id 5 (A-) can receive blood donations from 5 (A-) and 6 (O-). I have to build a search form that retreives potential blood donors. The form allows the user to search for specific blood type donors. If I search for blood type 5 (A-), the query should return all users that have 5 (A-) and 6 (O-) blood types, and the resulting list should display

MySQL: Usage of 'REGEXP' instead of 'FIND_IN_SET'

社会主义新天地 提交于 2019-12-25 01:45:03
问题 I am having limitation in using MySQL's FIND_IN_SET function for searching array in set. Hence thinking of using of REGEXP. However can anyone help me constructing it. E.g. My requirement SELECT * FROM table AS t WHERE FIND_IN_SET('1,2,3', t.list); Hence thinking of using REGEXP function to search array within set. SELECT * FROM table AS t WHERE t.list REGEXP '1,2,3'; Can anyone help me building this REGEXP. 回答1: You can do like this: SELECT * FROM table AS t WHERE t.list REGEXP '^9,|,9$|,9,'

mysql | Request from empty column and FIND_IN_SET

£可爱£侵袭症+ 提交于 2019-12-20 07:05:06
问题 I have a table: id name position status 1 A 1,2 1 2 B 1 1 3 C 1 4 D 2 1 Where: position column is a text field; My request is here: SELECT `id` FROM `table` WHERE `status`=1 AND `position` > '' AND `position` = FIND_IN_SET( 1, `position` ) OR `position` = FIND_IN_SET( 2, `position` ) This request will return: 1,2,3,4. This is a wrong as I need: 1,2,4 -> Condition: ( position > ''). Where is a problem and how to change my request? Thanks. 回答1: you dont need to check if position is empty while

MySQL Select query to fetch record base on list values

最后都变了- 提交于 2019-12-20 02:54:38
问题 I am using MySQL. I have 3 Table as below. Table : subject_Master -------------------------- subjectId | subjectShortName ---------------------------------- 1 | English 2 | French 3 | German 4 | Latin ---------------------------------- Table : class_Master ----------------------------------- classId | className ---------------------------------- 1 | Rose 2 | Dasy 3 | Lily Table : subjectAllocation ------------------------------------------ allocationId | classId | subjectId ------------------

MySQL Select query to fetch record base on list values

假如想象 提交于 2019-12-20 02:54:10
问题 I am using MySQL. I have 3 Table as below. Table : subject_Master -------------------------- subjectId | subjectShortName ---------------------------------- 1 | English 2 | French 3 | German 4 | Latin ---------------------------------- Table : class_Master ----------------------------------- classId | className ---------------------------------- 1 | Rose 2 | Dasy 3 | Lily Table : subjectAllocation ------------------------------------------ allocationId | classId | subjectId ------------------