find-in-set

MYSQL - GROUP_CONCAT AND FIND_IN_SET are mixing values/order?

六月ゝ 毕业季﹏ 提交于 2019-12-13 06:11:07
问题 I have the following problem: I try to select all the votes a user made and put them out in one column. I use GROUP_CONCAT for this, but somehow it is mixing the values order. This is the SQL code: SELECT GROUP_CONCAT(DISTINCT options.option_name SEPARATOR ',') AS selected, user_login.firstname, user_login.lastname, event.event_title FROM options, user_login, event, votes, questions WHERE event.id = ? AND questions.Event_id = event.id AND votes.user_id = user_login.id AND votes.question_id =

FIND_IN_SET with comma seperated values for sorting condition

本小妞迷上赌 提交于 2019-12-12 02:59:24
问题 I am using find_in_set for fetching data using below query and it works correctly. SELECT * FROM A WHERE FIND_IN_SET( column1, ( SELECT column1 FROM B WHERE id = 21) ); Here this query SELECT column1 FROM B WHERE id = 21 gives result like '175587,282329' but I want that '175587,282329' whichever highest value will come here that I should use.In this case,It would be 282329 .but Is will any number of comma seperated values. Thanks 回答1: Assuming TableA looks as that CREATE TABLE A ( id INT,

SQL Server 2014 equivalent to mysql's find_in_set()

情到浓时终转凉″ 提交于 2019-12-12 02:59:15
问题 I'm working with a database that has a locations table such as: locationID | locationHierarchy 1 | 0 2 | 1 3 | 1,2 4 | 1 5 | 1,4 6 | 1,4,5 which makes a tree like this 1 --2 ----3 --4 ----5 ------6 where locationHierarchy is a csv string of the locationIDs of all its ancesters (think of a hierarchy tree). This makes it easy to determine the hierarchy when working toward the top of the tree given a starting locationID. Now I need to write code to start with an ancestor and recursively find all

Usage of FIND_IN_SET in query [closed]

人盡茶涼 提交于 2019-12-12 01:48:58
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . $query=$this->db ->select(a.date,group_concat(s.name) ->from("tbl_attendance a,tbl_students s") ->WHERE ("FIND_IN_SET(s.student_id, a.attendance)")->group_by("a.date") ->get(); I wanted to know whether I have used the FIND_IN_SET and group_by functions correctly. Thanks in advance 回答1: FIND_IN_SET() returns the

Is there any difference (index selection? speed?) in find_in_set vs or

∥☆過路亽.° 提交于 2019-12-11 06:46:55
问题 Is there any difference (index selection? speed?) between: select * from table where x = 'a' or x = 'b' vs select * from table where find_in_set(x, 'a,b') Should I use one of those or are they equal? 回答1: FIND_IN_SET is a function call which should skip the index altogether. You should consider using SELECT * FROM `table` WHERE x IN ('a', 'b') instead. 回答2: you should avoid FIND_IN_SET when ever possible! In most cases it is used when columns are not normalized (e.g. csv in a cell). IN is

mysql FIND_IN_SET equivalent to postgresql

人盡茶涼 提交于 2019-12-08 08:21:31
问题 select * from folder f,uploads u where u.id=f.folderId and FIND_IN_SET('8', '15,9,13,27') Please tell to me equivalent to predefind or userdefined postgresql function 回答1: You shouldn't be storing comma separated values in the first place, but you can do something like this: select * from folder f join uploads u ON u.id = f.folderId where '8' = ANY (string_to_array(some_column,',')) string_to_array() converts a string into a real array based on the passed delimiter 回答2: select * from folder f

mysql FIND_IN_SET equivalent to postgresql

白昼怎懂夜的黑 提交于 2019-12-06 16:28:00
select * from folder f,uploads u where u.id=f.folderId and FIND_IN_SET('8', '15,9,13,27') Please tell to me equivalent to predefind or userdefined postgresql function You shouldn't be storing comma separated values in the first place, but you can do something like this: select * from folder f join uploads u ON u.id = f.folderId where '8' = ANY (string_to_array(some_column,',')) string_to_array() converts a string into a real array based on the passed delimiter Mesbah Gueffaf select * from folder f,uploads u where u.id=f.folderId and '8' in('15','9','13','27') The FIND_IN_SET() function in

difference between where_in and find_in_set

半腔热情 提交于 2019-12-02 14:18:20
问题 I am working on a join query in which I have to get the data from a column which contain the comma separated values.like allowed_activity contain 1,2,3,4,5,6 this the activity_id which is allowed. So In the query, I am checking that current activity is allowed or not and for that, I have used where_in and also tried find_in_set in where condition. Here is that part of the query: $this->db->where_in('a.allowed_activity',$activity_id); //And With FIND_IN_SET $this->db->where("FIND_IN_SET(

difference between where_in and find_in_set

爱⌒轻易说出口 提交于 2019-12-02 05:21:00
I am working on a join query in which I have to get the data from a column which contain the comma separated values.like allowed_activity contain 1,2,3,4,5,6 this the activity_id which is allowed. So In the query, I am checking that current activity is allowed or not and for that, I have used where_in and also tried find_in_set in where condition. Here is that part of the query: $this->db->where_in('a.allowed_activity',$activity_id); //And With FIND_IN_SET $this->db->where("FIND_IN_SET($activity_id, a.allowed_activity) !=",0); Problem or Confusion When I use where_in it doesn't give me the

Select Multiple Ids from a table

空扰寡人 提交于 2019-11-30 06:30:06
问题 I want to select some id's based on url string but with my code it displays only the first. If i write manual the id's it works great. I have a url like this http://www.mydomain.com/myfile.php?theurl=1,2,3,4,5 (ids) Now in the myfile.php i have my sql connection and: $ids = $_GET['theurl']; (and i am getting 1,2,3,4,5) if i use this: $sql = "select * from info WHERE `id` IN (1,2,3,4,5)"; $slqtwo = mysql_query($sql); while ($tc = mysql_fetch_assoc($slqtwo)) { echo $tc['a_name']; echo " - "; }