homepage Welcome to WebmasterWorld Guest from 54.163.84.199
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
Is this possible in Mysql
Elric99




msg:4188174
 9:14 am on Aug 17, 2010 (gmt 0)

If I have a table with 100 products in it, half are from Brand A, half are from Brand B. How do I say:

SELECT * FROM table_name
LIMIT 20
BUT ... show 10 products from Brand A and 10 products from Brand B

Maybe it's early but I can't quite get my head around how to write this query.

Thanks!

 

brotherhood of LAN




msg:4188216
 11:51 am on Aug 17, 2010 (gmt 0)

You can use the UNION operator, so something like this should be good.

SELECT * FROM table WHERE product = 'a' LIMIT 10
UNION
SELECT * FROM table WHERE product = 'b' LIMIT 10

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved