3

I just trying to know is this possible the function of MYSQL GROUP_CONCAT to return this type of data. Here is a scenario

SELECT GROUP_CONCAT(marks) AS `i need only 40 int in this column`  FROM marks

when i execute this Query the result will be show like this

enter image description here

Result required 40

6
  • no i need only 40 there is no average of 5 @SalmanA Commented Apr 4, 2012 at 12:25
  • 2
    Hard code 40 in your query (SELECT 40 FROM marks LIMIT 1), unless you have a reason we could understand. Commented Apr 4, 2012 at 12:25
  • i have a multiple value in one column and i need to extract only 40 also i mentioned my Question is this possible or not @SalmanA Commented Apr 4, 2012 at 12:29
  • GROUP_CONCAT does not make any sense without GROUP_BY Commented Apr 4, 2012 at 12:32
  • What is possible or not? Your question is totally unclear. Can you give a few sample rows and the expected output? If you only need a literal 40, a simple SELECT 40 LIMIT 1 will do. Otherwise you need to add a few more details to your question – as it stands it is totally unclear. Commented Apr 4, 2012 at 13:13

3 Answers 3

3

Try this:

select group_concat(m.marks) from 
    ( select distinct marks from marks limit 40 ) m
Sign up to request clarification or add additional context in comments.

2 Comments

I am not sure I understood your question correctly though... :-)
@knittl: I don't know. To me, it seems that OP wants only 40 integers, and not only integer 40. But as I stated in my previous comment: don't know if understood correctly what OP wants.
1

Advice first: normalize your database tables – a field should only contain a single value.

Now, the solution for your concrete problem: MySQL has the FIND_IN_SET function which should do what you want:

SELECT marks
FROM marks
WHERE FIND_IN_SET('40', marks)

3 Comments

Thanx for sharing your experience but that not my Question
@Samad: Then what exactly is your question?!
I still don't understand. GROUP_CONCAT creates a single string of multiple rows, when used in combination with GROUP BY. »[…] want to pick one element from comma separated field« ← which element? first? middle? last? matching a certain criteria?
0

Your syntax

SELECT GROUP_CONCAT(marks) AS `i need only 40 int in this column`  FROM marks

is working properly. You are giving GROUP_CONCAT(marks) the name i need only 40 int in this column, so it shows what you are saying through syntax.

" Result required 40 "

What does it means when you use group_concat and you want to record where the marks are 40? Why not use query like

select * from table_name where marks='40'

If group_concat is a compultion, then use

SELECT GROUP_CONCAT(marks) AS `i need only 40 int in this column`  FROM marks where marks='40'

8 Comments

i have already mentioned my Question is this possible or not if possible then how
your query is working properly what it have to, so whats the question arrived? means what do you whant to show in result.
i want to get 40 value in this column with the help of mysql functions
why not you using ` select * from table_name where marks='40' ` instead of group_concat,by the way why are you using group-concat, it will give you whole result not 40 only
i know this statement but that not my Question
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.