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

  • SEARCH
  • Home
  • 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 785099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:49:14+00:00 2026-05-14T20:49:14+00:00

I am tying to join the following 2 queries but I am having duplicated

  • 0

I am tying to join the following 2 queries but I am having duplicated …. it is possible to remove duplacted fro this:

(
SELECT bar_id, bar_name, town_name, bar_telephone, 
        (subscription_type_id *2) AS subscription_type_id
FROM bar, sportactivitybar, towns, subscriptiontype
WHERE sport_activity_id_fk =14
    AND bar_id = bar_id_fk
    AND town_id = town_id_fk
    AND subscription_type_id = subscription_type_id_fk
)
UNION 
(
SELECT bar_id, bar_name, town_name, bar_telephone, 
         subscription_type_id
FROM bar, towns, subscriptiontype
WHERE town_id = town_id_fk
    AND subscription_type_id = subscription_type_id_fk
)
ORDER BY subscription_type_id DESC , RAND( )

Please note that I need to omit those duplicates that will have a lower subscription_type_id

  • 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-05-14T20:49:15+00:00Added an answer on May 14, 2026 at 8:49 pm

    If I understand you correctly, a simple GROUP BY, witholding only the maxium subscription types should do the trick.

    SELECT  dupAlias.bar_id
            , dupAlias.bar_name
            , dupAlias.town_name
            , dupAlias.bar_telephone
            , MAX(dupAlias.subscription_type_id) AS subscription_type_id
    FROM    (
              SELECT  bar_id
                      , bar_name
                      , town_name
                      , bar_telephone
                      , (subscription_type_id *2) AS subscription_type_id
              FROM    bar
                      , sportactivitybar
                      , towns
                      , subscriptiontype
              WHERE   sport_activity_id_fk =14
                      AND bar_id = bar_id_fk
                      AND town_id = town_id_fk
                      AND subscription_type_id = subscription_type_id_fk
              UNION 
              SELECT  bar_id
                      , bar_name
                      , town_name
                      , bar_telephone
                      , subscription_type_id
              FROM    bar
                      , towns
                      , subscriptiontype
              WHERE   town_id = town_id_fk
                      AND subscription_type_id = subscription_type_id_fk
            ) dupAlias
    GROUP BY
            dupAlias.bar_id, dupAlias.bar_name, dupAlias.town_name, dupAlias.bar_telephone
    ORDER BY 
            dupAlias.subscription_type_id DESC , RAND( )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to execute the following SQL: SELECT * FROM Table2 INNER JOIN (SELECT
Trying to implement following queries in NHibernate QueryOver. SQL SELECT SUM(GrossChargeAmount) FROM Charges INNER
Im trying to make some queries, first, I do this one (and works): SELECT
I am trying to learn about MYSQL Joins but am having trouble figuring this
Using the following query: SELECT pe.prodtree_element_name_l, MAX(rs.resource_value) AS resource_value FROM prodtree_element pe LEFT JOIN
I have the following queries, QryStockOnHand SELECT QrySaleTot.Item, QrySaleTot.ProductID, [QryStockLevel].[Stock]-[QrySaleTot].[Quantity] AS StockOnHand FROM QryStockLevel
I have the following queries: Query 1: Select * from T10,T11,T12,T13,T14 where T10.C0 =
I am trying to join my users table with another table using the following
I have the following three tables. I am trying to inter link (join) among
I have the following code: Tag.find_all_by_company_id(4).each.collect{|tag| tag.name }.join(,) (Essentially I'm trying to build a

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.