If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Limit- mysql query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-11-12, 18:04
felito felito is offline
Registered User
 
Join Date: Apr 2011
Posts: 3
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
Reply With Quote
  #2 (permalink)  
Old 01-11-12, 18:27
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On