Oracle duplicate entries bases on Two columns - oracle

i need a query to get duplicate entries from table A on bases of two columns (Acol2 and Acol3) and Bcol3 from Table b where A.Acol4= B.Bcol2.
theefore two crequirements
1-select duplicats entries( on basis of columns Acol2 & Acol3) and Bcol3 from table A and table B
2- where A.Acol4= B.Bcol2
I am able to write query to get duplicate entries but unable to get bcol3 with condition 2.

create the join and then group by to find duplicates
SELECT a.acol2, a.acol3, b.bcol3
FROM a, b
WHERE a.acol4 = b.bcol2
GROUP BY a.acol2, a.acol3, b.bcol3
HAVING COUNT (*) > 1

Related

Sorting Cassandra Query Output Data

I am sure this is the most common problem with Cassandra.
Nevertheless:
I have this example table:
CREATE TABLE test.test1 (
a text,
b text,
c timestamp,
id uuid,
d timestamp,
e decimal,
PRIMARY KEY ((a),c, b, id)) WITH CLUSTERING ORDER BY (b ASC, compartment ASC);
My query:
select b, (toUnixTimestamp(d) - toUnixTimestamp(c))/1000/60/60/24/365.25 as age from test.test1 where a = 'x' and c > -2208981600000 ;
This works fine but I can't get the data sorted by column b which I need. I need all the entries in column b and their corresponding 'age's.
eg:
select b, (toUnixTimestamp(d) - toUnixTimestamp(c))/1000/60/60/24/365.25 as age from test.test1 where a = 'x' and c > -2208981600000 order by b;
gives the error:
InvalidRequest: Error from server: code=2200 [Invalid query] message="Order by currently only supports the ordering of columns following their declared order in the PRIMARY KEY"
I have tried different orders in the clustering columns and different options in the partition key but I get caught by some logic and just can't seem to outwit Cassandra to get what I want. If I get the sort order I want, I loose the ability to filter on column 'c'.
Is there some logic I am not applying here, or alternatively, what must I omit(?) to get a list of entries in column b with the corresponding age.
Short answer - it's impossible to sort data on arbitrary column using CQL, even if it's a part of the primary key. Cassandra sorts data first by first clustering column, then inside it by second, etc. (see this answer).
So the only workaround right now is to fetch all data & sort on the client side.

Append two tables with different sizes

I have table one with 5 columns and table two with 7 columns.
How can I append them into a new table with only the common columns (that is, the columns with common names)?
I tried all sorts of "Append Queries" in the Query Editor but it seems that it only works with exactly identical tables.
In DAX, UNION seems to have the same limitation.
Use Append Queries -> Append as New to create a new table.
The M function, Table.Combine(), will combine the columns where they are named the same and add columns with null values where they only exist in one table
Table.Combine({
Table.FromRecords({[Name = "David", Phone = "01235667886"]}),
Table.FromRecords({[Email= "me#gmail.com", Phone = "01124892522"]})
})
> Name Phone Email
> David 01235667886
> 01124892522 me#gmail.com

How do I update multiple records in Oracle?

I have millions of records in a table and I need to update particular records which have wrong values. How do I do it?
Example:
Si Item_Id
1 T21547856
2 T45200254
3 T54785000
Need to update like:
T21547856 = CS2541
T54785000 = CS5475
This is just an example. I have millions of records and need to update more than half a million.
One approach would be:
Create an index on item_id, then just do the updates. update table set item_id = 'CS2541' where itme_id = 'T21547856'
This works only item_ids are unique in your table.
After this, you may drop the index if you don't need it.
A second approach would be to create another table, B, with values to be updated:
si item_id
1 CS2541
3 CS5475
Then do a merge:
merge into your_table a
using b
on a.si=b.si
when matched then update set a.item_id=b.item_id;

SSRS - T-SQL - Concatenate multiple rows

I have T-SQL query that joins multiple tables. I am using that in SSRS as Dataset query. I am only selecting two columns, ID and Names. I have three records with same "ID" values but three different "Names" values. In SSRS, I am getting the first "Names" value and I need to concatonate all three values with same ID and have it in one cell on a table.
How would I go about doing that?
I am using lookup to combine cube + sql
Pulling ID straight from a table but using Case statement for Names to define alias.
You can accomplish this in TSQL either using PIVOT to get them as separate columns which you can then combine in the report cell, or you can use one of these concatenation methods to get all the names in one column.
For example, you can do this:
SELECT SomeTableA.Id,
STUFF(
(SELECT ',' + SomeTableB.Names AS [text()]
FROM SomeTable SomeTableB
WHERE SomeTableB.Id = SomeTableA.Id
FOR XML PATH('')), 1, 1, '' )
AS ConcatenatedNames
FROM SomeTable SomeTableA
INNER JOIN AnotherTable
ON SomeTableA.Id = AnotherTable.SomeId
...

Update One table Column with Values from Another table Having Similar

Hi Guys I have Two tables (MIGADM.CORPMISCELLANEOUSINFO and CRMUSER.PREFERENCES) and Each Has a field called PREFERENCE_ID and ORGKEY. I want to Update the Preference ID for MIGADM.CORPMISCELLANEOUSINFO with Preference_ID from CRMUSER.PREFERENCES for Each Corresponding ORGKEY. SO I wrote this Query;
update migadm.CORPMISCELLANEOUSINFO s set s.PREFERENCE_ID = (
select e.PREFERENCE_ID from crmuser.preferences e where s.ORGKEY = e.ORGKEY)
But I get:
ORA-01427: single-row subquery returns more than one row
What Should I do?
It means the columns you have selected are not unique enough to identify one row in your source table. Your first step would be to identify those columns.
To see the set of rows that have this problem, run this query.
select e.origkey,
count(*)
from crmuser.preferences e
group by e.origkey
having count(*) > 1
eg : for origkey of 2, let's say there are two rows in the preferences table.
orig_key PREFERENCE_ID
2 202
2 201
Oracle is not sure which of these should be used to update the preference_id column in CORPMISCELLANEOUSINFO
identify the row where the subquery returns more than one row (You could use REJECT ERROR clause to do it for instance) or use the condition 'where rownum = 1'.

Resources