logo
down
shadow

How to return unique records between two tables without using distinct and union?


How to return unique records between two tables without using distinct and union?

By : David
Date : November 22 2020, 10:40 AM
I wish did fix the issue. I actually solved the problem using analytic function+row_num. The query will choose the first record for each set of duplicates hence returning only the unique records.
code :
select * from
 (
    select ua.*,row_number() over (partition by p_id order by p_id ) row_num from 
    (
        select * from table1
        union all
        select * from table2
    )ua
) inner
where inner.row_num=1


Share : facebook icon twitter icon
Return addition of common records with unique records from 3 tables

Return addition of common records with unique records from 3 tables


By : user2938289
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I have 3 tables table1, table2 and table3 which don't have any relation between them. , Try this query:
code :
 SELECT name, sum(amount) FROM (
    (SELECT scname AS name, samount AS amount FROM table1)
    UNION ALL
    (SELECT raccname AS name, ramount AS amount FROM table2)
    UNION ALL
    (SELECT raccname2 AS name, ramount2 AS amount FROM table2)
    UNION ALL
    (SELECT pyaccname AS name, pyamount AS amount FROM table3)
    UNION ALL
    (SELECT pyaccname2 AS name, pyamount2 AS amount FROM table3)
) p GROUP BY name;
SQL return duplicate records as Distinct records and unique records together

SQL return duplicate records as Distinct records and unique records together


By : cwdii
Date : March 29 2020, 07:55 AM
wish of those help I am new to SQL and I'm having trouble solving a problem using one table to get two combined results. I have a table that has duplicate entries and individual entries. I would like my results to show the individual entries and to show the distinct entries of the duplicates. My table is something like this: , Solution to your problem:
code :
SELECT Date, Code, Units
FROM Table_Name
GROUP BY Date, Code, Units;
Date        Code     Units
2018-01-01  Bottles  12
2018-01-02  Trains   6
2018-01-05  Cars     11
2018-01-15  Boats    9
2018-01-16  Boats    7
2018-01-16  Plains   8
DAX Query Union Multiple Tables & Return Distinct

DAX Query Union Multiple Tables & Return Distinct


By : user2499649
Date : March 29 2020, 07:55 AM
seems to work fine Rather than recreate your SQL, there is DAX that already addresses your specific use case. The EXCEPT function returns a table where rows from the LEFT SIDE table do not appear in the RIGHT SIDE table.
code :
EVALUATE
DISTINCT (
    EXCEPT (
        SUMMARIZE ( CompletedJobs , CompletedJobs [Name]),
        SUMMARIZE ( ScriptDetails , ScriptDetails [ActivityName])
    )
)
What is the proper way to union tables to get set of unique records from all tables?

What is the proper way to union tables to get set of unique records from all tables?


By : user3656490
Date : March 29 2020, 07:55 AM
it helps some times Is the issue that the columns are different? If so, just pad them with nulls:
code :
select a, b, c, null as d from t1 union all
select a, b, c, null as d from t2 union all
select a, b, c, null as d from t3 union all
select a, b, c, null as d from t4 union all
select a, null as b, null as c, d from t5 union all
select a, null as b, null as c, d from t6 union all
select a, null as b, null as c, d from t7
Return records with all columns but with unique one of them (distinct)

Return records with all columns but with unique one of them (distinct)


By : Артем Григорьевич Ан
Date : March 29 2020, 07:55 AM
I hope this helps . Try this: http://www.sqlfiddle.com/#!4/9f1ae/10
Related Posts Related Posts :
  • SQL Server error: Column name or number of supplied values does not match table definition
  • How to find a table name which's column name consist cl_
  • Cannot access existing table from WCF Code
  • SQL CREATE VIEW Error
  • Many Statement in the same transaction PLSQL
  • Tables are not joining properly in sql server 2008
  • DB2 how to sum two column from two different table
  • SQL msAccess: list unfinished courses of a student
  • SQL Server delete multiple rows
  • Finding max(date) from the resultant query output
  • updating multiple columns using case statement in sql server
  • Nested SQL query having select subquery in update statement
  • "putting" a certain object to the screen from inside an array
  • Retrieve segment from value
  • Error while creating a table in oracle 11g
  • Transaction with Sequelize doesn't work
  • Search time complexity of this sql query
  • Is it possible to maximum occurences of a value for each key in my table all in one query?
  • Divide table into groups of 5000 based on rank
  • rolling back exec and sp_OA methods
  • How to convert multiple rows to one row in SQL Server?
  • How to use substring and charindex in google query language
  • Find table information where part of column matches char variable
  • Need to retrieve rows from table where the following condition was not satisfied column A = column B and column B = colu
  • Assigning an index to a constraint
  • Retrieve records from multiple Records returned by Sub-Query
  • SQL DELETE group of records based on opposite group being empty
  • SQL GetDate() returns wrong time
  • Total sales amount for customers in cities
  • SQL Server -- updating the `sys.*` tables and not just reading them
  • SQL Order By using concat
  • SQL server 2008 - subquery returned more than one value
  • Group Data Hourly and Insert Into a Summary Table in Postgres
  • Execute SQL Server Pass-Through Query From Access VBA
  • MS Access SQL Transform Aggregate Manipluation of Values for Pivot
  • SQL "if exists..." dynamic query
  • HANA: Split string?
  • Create a list of dates and match records to the list
  • Why won't SQL round correctly from my batch script?
  • SQLServer - Multiple PIVOT on same columns
  • Update a table foreign keys by substituting by a lookup from the result of another table
  • Deleting rows in a single database table based on the values of other rows
  • Search and replace part of string in database - what are the pitfalls?
  • How could I generate auto insert function SEAT_NO like A1,A2.... B1,B2 in sql server
  • whats a good way to optimize a table? SQL server 2k8
  • Sql server dynamic sequences
  • JPQL Query - object that's in one list and isn't in another
  • How to sort lines in select resquest to don't have multiple same lines
  • SQL Server : new and old value from history table in one row
  • SQL select bottom half
  • How to sum order cost
  • Repeatedly creating and dropping temp table of the same name
  • oracle yyyyiw glitch
  • ORDER BY id IN Subquery
  • SQL max concurrent sessions per hour of day
  • postgresql events per hours
  • database db2: Group by custom date range
  • How to allow letters only in VARCHAR2 column (Oracle SQL)
  • What is the equivalent of T-SQL ISNUMERIC function in HANA Sqlscript?
  • Send SQL Query and Wait For Response VB.NET
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org