Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2011
    Posts
    3

    Unanswered: Limit- mysql query

    I would like to know how can i limit the output by the number of id_offers and not the number of rows. For example

    Code:
      SELECT  A.id_offer, T.tags  
            		FROM offer A
            		INNER JOIN offer_has_tags Z
                    ON A.id_offer = Z.offer_id_offer
                    
              		INNER JOIN tags T
                    ON Z.tags_id_tags = T.id_tags
                    
            		WHERE state = 0 
            		ORDER BY date
            		DESC LIMIT 0, 10
    output:
    Code:
          id_offer 	tags
            77 	     xx 
            76 	     xx 
            76 	     xx 
            75 	     xx 
            75 	     xx 
            74 	     xx 
            74 	     xx
            73 	     xx
            73 	     xx
            72 	     xx

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by felito View Post
    I would like to know how can i limit the output by the number of id_offers and not the number of rows.
    may i ask what you're going to do with the tags?

    perhaps a GROUP_CONCAT of the tags for each id is feasible?

    so instead of producing this --
    Code:
    id_offer  tags
        77       xx 
        76       xx 
        76       xx 
        75       xx 
        75       xx 
        74       xx 
        74       xx
        73       xx
        73       xx
        72       xx
    the query will produce this --
    Code:
    id_offer  tags
        77       xx 
        76       xx,xx
        75       xx,xx
        74       xx,xx
        73       xx,xx
        72       xx
    and then LIMIT will work on the summary rows, one per id
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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