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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:04:52+00:00 2026-06-01T02:04:52+00:00

When I execute my select union select, I get the correct number or rows

  • 0

When I execute my “select union select”, I get the correct number or rows (156)
Executed independently, select #1 returns 65 rows and select #2 returns 138 rows.

When I use this “select union select” with an Insert into, I get 203 rows (65+138) with duplicates.

I would like to know if it is my code structure that is causing this issue ?

INSERT INTO dpapm_MediaObjectValidation (mediaobject_id, username, checked_date, expiration_date, notified)

    (SELECT FKMediaObjectId, CreatedBy,@checkdate,dateadd(ww,2,@checkdate),0
    FROM dbo.gs_MediaObjectMetadata
    LEFT JOIN gs_MediaObject mo
    ON gs_MediaObjectMetadata.FKMediaObjectId = mo.MediaObjectId
    WHERE UPPER([Description]) IN ('CAPTION','TITLE','AUTHOR','DATE PHOTO TAKEN','KEYWORDS')
    AND FKMediaObjectId >= 
        (SELECT TOP 1 MediaObjectId 
            FROM dbo.gs_MediaObject 
            WHERE DateAdded > @lastcheck 
            ORDER BY MediaObjectId) 
    GROUP BY FKMediaObjectId, CreatedBy
    HAVING count(*) < 5

    UNION

    SELECT FKMediaObjectId, CreatedBy,getdate(),dateadd(ww,2,getdate()),0
    FROM gs_MediaObjectMetadata yt
    LEFT JOIN gs_MediaObject mo
    ON yt.FKMediaObjectId = mo.MediaObjectId
    WHERE UPPER([Description]) = 'KEYWORDS'
    AND FKMediaObjectId >= 
        (SELECT TOP 1 MediaObjectId 
            FROM dbo.gs_MediaObject 
            WHERE DateAdded > @lastcheck
            ORDER BY MediaObjectId) 
    AND NOT EXISTS
            (
            SELECT  *
            FROM    dbo.fnSplit(Replace(yt.Value, '''', ''''''), ',') split
            WHERE   split.item in (SELECT KeywordEn FROM gs_Keywords) or split.item in (SELECT KeywordFr FROM gs_Keywords)
            )
    )

I would appreciate any clues into resolving this problem …

Thank you !

  • 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-01T02:04:53+00:00Added an answer on June 1, 2026 at 2:04 am

    The UNION keyword should only return distinct records between the two queries. However, if I recall correctly, this is only true if the datatypes are the same. The date variables might be throwing that off. Depending on the collation type, whitespace might be handled differently as well. You might want to do a SELECT DISTINCT on the dpapm_MediaObjectValidation table after doing your insert, but be sure to trim whitespace from both sides in your comparison. Another approach is to do your first insert, then on your second insert, forgo the UNION altogether and do a manual EXISTS check to see if the items to be inserted already exist.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

1) require 'sqlite3' db = SQLite3::Database.new('development.sqlite3') db.results_as_hash = true; rows = db.execute( SELECT *
I execute a select to get the structure of a table. I want to
I'd like to execute something like this on my MySQL server: SET @id=(SELECT id
If you execute this query SELECT 'test-a1' AS name1, 'test-a2' AS name2 the result
I am facing this problem. I have a stored procedure which returns 6 rows
I wanted to do an insert into with a union, and someone suggested this:
cursor.execute(SELECT user_id FROM myapp_location WHERE\ GLength(LineStringFromWKB(LineString(asbinary(utm), asbinary(PointFromWKB(point(%s, %s)))))) < %s\ ,(user_utm_easting, user_utm_northing, 500)); This
I have the cursor with the query statement as follows: cursor.execute(select rowid from components
am reading out of a database with the following python script: cur.execute(SELECT * FROM
I'm trying to debug a SQL statement generated with sqlite3 python module... c.execute(SELECT *

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.