SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Concat

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2009
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Concat

    Hi

    I'm usinng GROUP_CONCAT to concatinate query results,
    Code:
     
    eg : SELECT  CAST(GROUP_CONCAT(`timestamp` SEPARATOR "','")AS BINARY) as `timestamp`
    and it results

    Code:
    2010-03-05 04:38:01','2010-03-05 04:38:05','2009-12-24 04:15:49
    i like to run above query like this

    Code:
    Select * from demo where demo IN(SELECT  CAST(GROUP_CONCAT(`timestamp` SEPARATOR "','"))
    if you see the results single quotes is missing from first and last position.

    so how can we concatinate single quotes at both ends

    Thanks in advance

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2009
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
     SELECT  CONCAT("'",CAST(GROUP_CONCAT(`timestamp` SEPARATOR "','")AS BINARY),"'") as `timestamp`
    it works now

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2009
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have certain doubt my subquery is not working in "IN"

    It does not returns any results.

    how can i give subquery properly inside "IN"

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Code:
    SELECT * 
      FROM demo 
     WHERE demo IN ( SELECT `timestamp`
                       FROM sometable )
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2009
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That was mistake from my side , we dont have to GROUP_CONCAT when using subquery inside "IN"

    thanks for the help


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •