group-concat

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 ------------------

CommunicationsException: Communications link failure

一个人想着一个人 提交于 2019-12-18 06:40:07
问题 I used java to query some records from Mysql. But in some querys of one duration, i meet a problem which make query failed, but in others , it query successful. The error message is next: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet successfully received from the server was 90 milliseconds ago. The last packet sent successfully to the server was 1,674 milliseconds ago. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native

LEFT JOIN after GROUP BY?

。_饼干妹妹 提交于 2019-12-18 04:07:15
问题 I have a table of "Songs", "Songs_Tags" (relating songs with tags) and "Songs_Votes" (relating songs with boolean like/dislike). I need to retrieve the songs with a GROUP_CONCAT() of its tags and also the number of likes (true) and dislikes (false). My query is something like that: SELECT s.*, GROUP_CONCAT(st.id_tag) AS tags_ids, COUNT(CASE WHEN v.vote=1 THEN 1 ELSE NULL END) as votesUp, COUNT(CASE WHEN v.vote=0 THEN 1 ELSE NULL END) as votesDown, FROM Songs s LEFT JOIN Songs_Tags st ON (s.id

Converting MySQL code to Access: GROUP_CONCAT and a triple JOIN

不想你离开。 提交于 2019-12-17 19:57:21
问题 I'm having a really hard time translating a piece of MySQL-code to Access. I'm trying to use one of the queries found in the Sakila (MySQL) Database for an Access project I'm working on. First of all, the GROUP_CONCAT function doesn't work at all. After some Google searches I found out that Access doesn't support this function but I couldn't find a working alternative. CONCAT however could be replaced by a few '+' operators. Then comes the triple LEFT JOIN which kept returning a missing

MySQL GROUP_CONCAT escaping

a 夏天 提交于 2019-12-17 18:19:57
问题 (NOTE: This question is not about escaping queries, it's about escaping results) I'm using GROUP_CONCAT to combine multiple rows into a comma delimited list. For example, assume I have the two (example) tables: CREATE TABLE IF NOT EXISTS `Comment` ( `id` int(11) unsigned NOT NULL auto_increment, `post_id` int(11) unsigned NOT NULL, `name` varchar(255) collate utf8_unicode_ci NOT NULL, `comment` varchar(255) collate utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), KEY `post_id` (`post_id`) )

How to hack MySQL GROUP_CONCAT to fetch a limited number of rows?

人盡茶涼 提交于 2019-12-17 07:32:49
问题 I somehow need this feature,but MySQL doesn't support it at this moment. I'm using GROUP_CONCAT(CONCAT(...)) to generate a xml-like stuff. But when the size exceeds the limit,the xml is just broken! So I have to somehow make it only retrieve 5 rows ! 回答1: I've worked around this using SUBSTRING_INDEX . For example: SELECT SUBSTRING_INDEX(GROUP_CONCAT(Field1 SEPARATOR ','), ',', [# of elements to return]) FROM Table1; 回答2: An example for Charles answer: basic: SELECT GROUP_CONCAT( field ) FROM

GROUP_CONCAT with limit

拜拜、爱过 提交于 2019-12-17 05:01:31
问题 I have table with player -s in many-to-many relation with skill -s The goal is to list the players and their "top 3 skills" with a single query. fiddle create table player( id int primary key ); create table skill( id int primary key, title varchar(100) ); create table player_skills ( id int primary key, player_id int, skill_id int, value int ); Query: SELECT p.id, group_concat(s.title SEPARATOR ', ') as skills FROM player p LEFT JOIN player_skills ps ON ps.player_id = p.id LEFT JOIN skill s

GROUP_CONCAT with limit

人盡茶涼 提交于 2019-12-17 05:00:03
问题 I have table with player -s in many-to-many relation with skill -s The goal is to list the players and their "top 3 skills" with a single query. fiddle create table player( id int primary key ); create table skill( id int primary key, title varchar(100) ); create table player_skills ( id int primary key, player_id int, skill_id int, value int ); Query: SELECT p.id, group_concat(s.title SEPARATOR ', ') as skills FROM player p LEFT JOIN player_skills ps ON ps.player_id = p.id LEFT JOIN skill s

MySql duplicated values in a join using GROUP_CONCAT

偶尔善良 提交于 2019-12-13 17:26:11
问题 Let's say I have this schema : _________ _________ | Table 1 | | Table 2 | |---------| _______ ________|---------| | id_a |___ | link1 | | | id_b | | name | | |-------| | | info | |_________| |_____| id_a |___| | data | | | id_b | |_________| | |_______| | | _______ |______________| link2 |_______ |-------| | | id_a | | _________ | id_c | |__| Table 3 | |_______| |---------| | id_c | | email | |_________| With these informations in the database : Table 1 _____________ | id_a | name | |------|

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 =