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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:27:46+00:00 2026-05-28T14:27:46+00:00

I have two tables like the following : parameters1 +——+—–+ | cod | des

  • 0

I have two tables like the following :

parameters1

+------+-----+
| cod  | des |
+------+-----+
|  1   | aaa |
|  2   | bbb |
|  3   | ccc |

parameters2

+------+-----+
| cod  | des |
+------+-----+
|  1   | mmm |

I usually JOIN the result set of this two tables with an UNION in this way :

SELECT  cod,  des 
FROM parameters1
UNION 
SELECT  cod,  des 
FROM parameters2

and i get this result set :

+------+-----+
| cod  | des |
+------+-----+
|  1   | aaa |
|  2   | bbb |
|  3   | ccc |
|  1   | mmm |

I want to limit the UNION duplicate checking only to the cod column, so i want to avoid that the 1 cod get duplicated in the result set (when there is a record with different name and the same cod), i want to get the name from the first table (parameters1) :

+------+-----+
| cod  | des |
+------+-----+
|  1   | aaa |
|  2   | bbb |
|  3   | ccc |

UPDATE
If i remove the record 1 from the parameters1 table(DELETE FROM parameters1 WHERE cod = 1) i should get this result set :

+------+-----+
| cod  | des |
+------+-----+
|  1   | mmm |   ---> FROM parameters2
|  2   | bbb |
|  3   | ccc |

Is it possible to limit the duplicate checking of a UNION to only one field or some fields ? How ?

The solution should work on a multidatabase environment (MSSQL, PostgreSQL, MySQL).

  • 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-28T14:27:47+00:00Added an answer on May 28, 2026 at 2:27 pm
    SELECT  cod, des 
    FROM parameters1 p1
    UNION ALL
    SELECT  cod, des 
    FROM parameters2 p2
    WHERE NOT EXISTS (
        SELECT 1
        FROM parameters1 p1sub
        WHERE p1sub.cod = p2.cod
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use SQL Server 2000. Suppose I have two tables like the following: Area
I have two tables that look like following: RELEASE TABLE name asin MATCHES TABLE
I have two tables like the following hotels ------ hotelID hotelName Second table operators
I have two MySql tables like the following: Cat ------ id : INT NOT
I have two tables like the following: position ------------ position_id int(9) company_id int(9) description
I have two tables like the ones below. I need to find what exchangeRate
I have two tables like of this structure: content (content_id, content_type, user_id, time, comment_count)
Say that I have two tables like those: Employers (id, name, .... , deptId).
Let's say I have two tables that look like this: TH TH TH TH
I have two tables which looks something like this Table Queue int ID; string

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.