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 8983467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:50:53+00:00 2026-06-15T20:50:53+00:00

I have this statement: SELECT * FROM sgtn WHERE sgtn_kun_id IN (SELECT DISTINCT kun_id

  • 0

I have this statement:

SELECT *
  FROM sgtn
 WHERE sgtn_kun_id IN (SELECT DISTINCT kun_id
                         FROM sgtn, kun
                        WHERE kun.kun_e_mail IN (LONG LIST OF EMAILS)
                              AND sgtn_kun_id = kun_id)

       AND sgtn_strasse IN (SELECT sgtn.sgtn_strasse
                              FROM sgtn
                             WHERE sgtn_kun_id IN (SELECT DISTINCT kun_id
                                                     FROM sgtn, kun
                                                    WHERE kun.kun_e_mail IN (LONG LIST OF EMAILS)
                                                          AND sgtn_kun_id = kun_id)

                             GROUP BY sgtn.sgtn_strasse
                            HAVING COUNT(sgtn_strasse) > 2);

LONG LIST OF EMAILS is i.e.:
‘abc@domain.com’,
‘def@domain.com’,
.
.
.
‘xyz@domain.com’

As you can see I repeat some part of subquerys in this query.

I’m wondering if and how can I replace LONG LIST OF EMAILS. It occurs in my statement twice. Would it be possible to edit this query, so that the mentioned LONG LIST OF EMAILS occurs once?

  • 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-15T20:50:54+00:00Added an answer on June 15, 2026 at 8:50 pm

    First, you don’t need to use

    IN (SELECT DISTINCT kun_id
        FROM sgtn, kun
        WHERE kun.kun_e_mail IN (LONG LIST OF EMAILS)
        AND sgtn_kun_id = kun_id)
    

    it is enough

    IN (SELECT kun_id
        FROM kun
        WHERE kun.kun_e_mail IN (LONG LIST OF EMAILS))
    

    the rows having multiple sgtn_strasse and email in your list can be detected with

    select * from (
      SELECT s.*, count(*) over (partition by sgtn_strasse) cnt_strasse
      FROM sgtn s
      WHERE sgtn_kun_id IN (SELECT kun_id
                           FROM kun
                           WHERE kun.kun_e_mail IN (LONG LIST OF EMAILS))
      )
    WHERE cnt_strasse > 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this SQL statement: SELECT * FROM history WHERE (fk_person = 2119) AND
We have this statement: (SELECT res_bev.bev_id, property_value.name AS priority FROM res_bev, bev_property, property_value WHERE
I have this very simple sql statement: SELECT max_dose FROM psychotropes WHERE (patient_meds.psychotrope =
I have a site with a SELECT statement like this: SELECT * FROM MyTable
I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0;
I have a SELECT statement like this: SELECT T1.COD, T1.NAME, (SELECT MAX(T2.DATA) FROM dbo.TAB2
I have this ugly SELECT statement : Select 'Urbain' as Véhicule, Count( DISTINCT Plaintes.IDEvenements)
i have this statement in access: SELECT * FROM accountsnew WHERE [Panels] not like
i have this sql statement in access: SELECT * FROM (SELECT [Occurrence Number], [1
I have this SQL-Statement: SELECT Geburtsdatum FROM Kunde WHERE Geburtsdatum BETWEEN '1993-01-01' AND '2000-01-01'

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.