Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use GROUP_CONCAT in a CONCAT in mysql

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 275
    Comment on it

    GROUP_CONCAT will always return a string value . It can be easily explain by the example.

    Example:

      bookid    | bookname    | isbnno   | cateid    | autid     |  pubid 
    
        | BK001   | Introduction to Electrodynamics     | 0000979001  | CA001   | AUT001 | P003   
        | BK001  | Introduction to Electrodynamics    |  0000979002  | CA002   | AUT002 | P002
        | BK003   | Guide to Networking                 | 0000979003  | CA003   | AUT003 | P002
        | BK004   | Transfer  of Heat and Mass          | 0000979004  | CA002   | AUT004 | P004
        | BK005   | Conceptual Physics                  | 0000979005  | CA001   | AUT005 | P006
        | BK006   | Fundamentals of Heat                | 0000979006  | CA001   | AUT006 | P005  
        | BK007   | Advanced 3d Graphics                | 0000979007  | CA003   | AUT007 | P002
        | BK008   | Human Anatomy                       | 0000979008  | CA005   | AUT008 | P006 
        | BK009   | Mental Health Nursing               | 0000979009  | CA005   | AUT009 | P007
        | BK010   | Fundamentals of Thermodynamics      | 0000979010  | CA002   | AUT010 | P007 
    

    This is book table.

    mysql_ SELECT pubid,GROUP_CONCAT(CATEID)
        -> FROM book
        -> GROUP BY pubid;
    +--------+-----------------------+
    | pubid | GROUP_CONCAT(CATEID) |
    +--------+-----------------------+
    | P001   | CA002,CA004           | 
    | P002   | CA003,CA003           | 
    | P003   | CA001,CA003           | 
    | P004   | CA005,CA002           | 
    | P005   | CA001,CA004           | 
    | P006   | CA005,CA001           | 
    | P007   | CA005,CA002           | 
    | P008   | CA005,CA004           | 
    +--------+-----------------------+
    

    This will explain the use of GROUP_CONCAT.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: