Results 1 to 3 of 3

 

Thread: How would you write this query?

  1. #1
    Registered User

    Status
    Offline
    Join Date
    Sep 2003
    Posts
    315
    Thanks
    28
    Thanked 19 Times in 16 Posts


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

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

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

    Thanks

  2. #2
    quids4free's Avatar
    Registered User

    Status
    Offline
    Join Date
    Aug 2005
    Posts
    329
    Thanks
    38
    Thanked 28 Times in 26 Posts
    Not sure if you can do that in a single query, it might be 2 queries LIMIT 10 just using

    WHERE merchant LIKE merchant_a / merchant_b

  3. #3
    Registered User

    Status
    Offline
    Join Date
    Jun 2004
    Posts
    145
    Thanks
    0
    Thanked 2 Times in 1 Post
    Think this should work:

    (SELECT product_id, product_name FROM table_name WHERE merchant_id = 1 LIMIT 10)
    UNION (SELECT product_id, product_name FROM table_name WHERE merchant_id = 2 LIMIT 10)

    Just need to remember to ensure the field names in both selects are the same

    Cheers

  4. The Following 2 Users Say Thank You to amcd78 For This Useful Post:

    Tobman (17-08-10), umbrella-technologies (17-08-10)



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. FT Write Up On SpeedSell
    By John Jupp in forum Affiliate Marketing Lounge
    Replies: 0
    Last Post: 06-04-09, 09:42 PM
  2. What should I write about?
    By BFG 9000 in forum Affiliate Marketing Lounge
    Replies: 7
    Last Post: 23-03-09, 10:38 AM
  3. Mod Re-write issues
    By andy_cwz in forum Programming
    Replies: 10
    Last Post: 20-11-08, 02:26 PM
  4. php mysql query based on previous query?
    By andy_jacko in forum Programming
    Replies: 2
    Last Post: 24-05-07, 08:47 AM
  5. URL re-write
    By PriceInspector in forum Affiliate Marketing Lounge
    Replies: 2
    Last Post: 09-05-07, 08:58 AM

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
  •  
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2