Query Master
Query Master

Reputation: 7097

mysql group_concat issue

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

Upvotes: 3

Views: 417

Answers (3)

Ankit Sharma
Ankit Sharma

Reputation: 4071

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'

Upvotes: 0

knittl
knittl

Reputation: 265221

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)

Upvotes: 1

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181280

Try this:

select group_concat(m.marks) from 
    ( select distinct marks from marks limit 40 ) m

Upvotes: 3

Related Questions