Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8245701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:16:21+00:00 2026-06-07T22:16:21+00:00

Please consider the following table structure and data: +——————–+————-+ | venue_name | listed_by |

  • 0

Please consider the following table structure and data:

+--------------------+-------------+
|     venue_name     |  listed_by  |
+--------------------+-------------+
| My Venue Name      |      1      |
| Another Venue      |      2      |
| My Venue Name      |      5      |
+--------------------+-------------+ 

I am currently using MySQL’s GROUP BY function to select only unique venue names. However, this only returns the first occurance of My Venue Name, but I would like to return it based on a condition (in this case where the listed_by field has a value > 2.

Essentially here’s some pseudo-code of what I’d like to achieve:

Select all records
Group by name
if grouped, return the occurance with the higher value in listed_by

Is there an SQL statement that will allow this functionality?

Edit: I should have mentioned that there are other fields involved in the query, and the listed_by field needs to be used elsewhere in the query, too. Here is the original query that we’re using:

SELECT  l1.field_value AS venue_name, 
    base.ID AS listing_id,
        base.user_ID AS user_id,
        IF(base.user_ID > 1, 'b', 'a') AS flag,
        COUNT(img.ID) AS img_num
        FROM ( listingsDBElements l1, listingsDB base )
        LEFT JOIN listingsImages img ON (base.ID = img.listing_id AND base.user_ID = img.user_id and img.active = 'yes')
        WHERE  l1.field_name = 'venue_name'
               AND l1.field_value LIKE '%name%'
               AND base.ID = l1.listing_id
               AND base.user_ID  = l1.user_id
               AND base.ID = l1.listing_id
               AND base.user_ID  = l1.user_id
               AND base.active = 'yes'
    GROUP BY  base.Title  ORDER BY  flag desc,img_num desc
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:16:24+00:00Added an answer on June 7, 2026 at 10:16 pm

    As long as you didn’t mention other fields – here is the simplest solution:

      SELECT venue_name,
             MAX(listed_by)
        FROM tblname
       WHERE listed_by > 2
    GROUP BY venue_name
    

    With other fields it could look like (assuming there is no duplicates in venue_name + listed_by pairs):

        SELECT *
          FROM tblname t1
    INNER JOIN (SELECT venue_name,
                       MAX(listed_by) max_listed_by
                  FROM tblname
                 WHERE listed_by > 2
              GROUP BY venue_name) t2 ON t1.venue_name = t2.venue_name
                                     AND t1.listed_by = t2.max_listed_by
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please consider the following table (created using a corresponding entity) request ------- id requestor
Please consider following sample table structure: +-------------------------------+--------------+------+-----+---------+-------+ | Field | Type | Null |
Please Consider the following table : As you can see the Name column has
Please consider the following view: <p>Count <span data-bind=text: unreadCount()>&nbsp;</span></p> <div data-bind='template: { name: conversationTemplate,
Please consider the following table structure on Oracle: create table DOCS ( DOC_NO NUMBER
Please consider the following two entities: @Entity @Table(name = PROFILE) public class Profile extends
Please consider the following tweets table: tweet_id user_id text ---------------------------- 1 1 lorem ipsum
Please consider the following SQL Server table and stored procedure. create table customers(cusnum int,
Please consider the following scripts. Create Table: IF OBJECT_ID('Colortable') IS NOT NULL DROP TABLE
Please consider the following HTML: <td> Some Text <table>.....</table> </td> I need to manipulate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.