SQL query to get non-unique values
Hello
I'm using oracle 11g.
I have a table (T1) with data below and you want to insert the value in another table (T2).
CITY STATE
--------------- --
San Francisco CA
Palo Alto CA
Sarasota FL
New York NY
Boston NY
Boston CO
A unique constraint on the city and the State of the columns are given in table 2.
I want to filter non-unique records before inserting data in table 2 to avoid the UNIQUE constraint exception.
Thus, in the example above, the query should display subfolders
Boston NY
Boston CO
any ideas?
Thank you
Hello
EmAar says:
Sorry Chris/Frank, I should have been more specific.
Here is an actual table data.
description of the category
Costumes of a1
Costumes of a1
Costumes of a1
A9 crew sweats
A9 crew sweats
CK recreation Rep
CK Rep Tees
K9 Casual
Formal K9
K9 TRAIL RUNNING
As you can see, the category A1 and A9 are duplicated with the same description. On the other hand, CK & K9 have different descriptions.
I need a query to display CK & K9 because they have different descriptions against the same category.
hope that make sense?
It makes sense, but it's still vague; you really need to post CREATE TABLE and INSERT statements for entry and the exact result wish you get.from of these data.
My best guess is that you want:
SELECTED category
OF THE real
GROUP BY category
After HAVING COUNT (DISTINCT description) > 1
;
Tags: Database
Similar Questions
-
Dynamic SQL query to get the unique value of list in a column
I have two tables: tblWorkers and tblSkills. tblWorkers has a column, skills, which is populated by a field of multiple-checkbox with one or more skill_IDs of tblSkills, so each tblWorkers.Skills consists of a list of one or more comma-delimited values. For any Skill_ID, I need to generate a list of all workers with the appropriate skills, so I tried to do something in the direction of SELECT WorkerName FROM tblWorkers WHERE IN of skills (skills, #FORM. Skill_ID #)... or WHERE skills (ListFind (skills, #FORM. Skill_ID #))... etc.? My results (once I have had data type mismatches of the road) return all workers, not just those with the desired skills. There must be an easy way to do... How people with a little more experience CF/SQL I do this?> each tblWorkers.Skills consists of a list of one or more comma-delimited values
This is your problem. You store a list of values that you want to access power/query separately in a single column. You will have to burst in a separate table.
TblWorkersTblSkills
TblWorkerSkills
mapping table of many workers with skills.If you do not change your data model now, you will constantly be butting your head against that.
-
Index on non unique values in order to avoid the full table scan
I have a table with > 100 k records. The table is updated only during the race every night. All columns except one have non - unique values and I am querying the table with this request.
COL3 - non - unique values - only 40 distinct values
unique values - no - COL4 - 1000 distinct values
last_column - 100 k unique values
Select last_column in the table_name where in (...) col3 or col4 (...)
I tried to create a Bitmap index individually on col3 and col4 and also combined. However, in both cases, it performs a full table scan.
Please, help me optimize this query as it is used in the term altogether the system and the cost of the query is very high around 650.
I don't have much experience with popular indexes then all tracks.
Thank you
Sensey
Published by: user13312817 on November 7, 2011 11:32An alternative might be to use a union instead and the 2 index:
create index my_index1 on my_table (col3, last_column) compress 1;
create index my_index2 on my_table (col4, last_column) compress 1;Select last_column from my_table
where col3 in (...)
Union
Select last_column from my_table
where col4 (...)In other words, if the UNION would apply here whereas in double values for last_column will be deleted.
-
SQL query to get the numbers from 0 to 99
How can we write a sql query to get values from 0 to 99... This should not come from any tableSELECT LEVEL - 1 FROM DUAL CONNECT BY LEVEL <= 100 /
SY.
-
SQL query to get the range of Date values
Hello
The database is Oracle11i.
I'm looking for a way to generate a list of the dates of a fixed date in the past (could be hardcoded) at the time of the day (sysdate).
In other words, if the fixed date is June 19, 2011, and assuming today ' today is June 24, 2011 the SQL must be able to generate the
Next: -.
June 19, 2011
June 20, 2011
June 21, 2011
June 22, 2011
June 23, 2011
June 24, 2011
And the constraint is that I can not make any change to the database in question. I can only shoot a (SELECT) SQL query. NO.
use time dimension type of approach (time dimension is not available here) and no procedure, etc. from PL/SQL. Is it possible?
Thank youJaimeen Shah wrote:
HelloThe database is Oracle11i.
I'm looking for a way to generate a list of the dates of a fixed date in the past (could be hardcoded) at the time of the day (sysdate).
In other words, if the fixed date is June 19, 2011, and assuming today ' today is June 24, 2011 the SQL must be able to generate the
Next: -.
June 19, 2011
June 20, 2011
June 21, 2011
June 22, 2011
June 23, 2011
June 24, 2011And the constraint is that I can not make any change to the database in question. I can only shoot a (SELECT) SQL query. NO.
use time dimension type of approach (time dimension is not available here) and no procedure, etc. from PL/SQL. Is it possible?
Thank you
SQL> def date_start = '13/11/2010' SQL> def date_end = '22/11/2010' SQL> with 2 data as ( 3 select to_date('&date_start', 'DD/MM/YYYY') date1, 4 to_date('&date_end', 'DD/MM/YYYY') date2 5 from dual 6 ) 7 select to_char(date1+level-1, 'DD/MM/YYYY') the_date 8 from data 9 connect by level <= date2-date1+1 10 / THE_DATE ---------- 13/11/2010 14/11/2010 15/11/2010 16/11/2010 17/11/2010 18/11/2010 19/11/2010 20/11/2010 21/11/2010 22/11/2010
-
Hello world
I want a little help to get some unique records in the table. I know that it can be very easy, but I don't know why I can't
Please help me
I'm working on Oracle 11 g DB and I use the plsql allround automation tool
I want to give example so that it will be very easy to understand
Table1 below.
CREATE THE TABLE1 TABLE:
(contract not null, number (10))
number (10) client.
delivery_type number (10));
insert into table1 values (1,1,1);
insert into table1 values 2.2.1;
insert into table1 values (2,22,1);
insert into table1 values (3.3.1);
insert into table1 values (3,33,1);
insert into table1 values (3,333,1);
Select * from table1;
CONTRACT CUSTOMER DELIVERY_TYPE 1 1 1 1 2 2 2 1 3 2 22 1 4 3 3 1 5 3 33 1 6 3 333 1 as you can see for the contract 2 and 3 I get 2 & 3 lines (since the clients are different I agree we receive multiple contracts)
but in that contract 2 and 3 I don't want that these contracts including a corresponding customers in another table with a type_code = "email".
create the table2 table
(customer number (10),)
Type_Code varchar2 (10));
insert into table2 values (22, 'EMAIL');
insert into table2 values (33, 'EMAIL');
insert into table2 values (333, 'EMAIL');
Select * from table2;
CUSTOMER TYPE_CODE 1 22 E-mail 2 33 E-mail 3 333 E-mail now I want a query that gives me the result like this
but I want the result like this
CONTRACT CUSTOMER DELIVERY_TYPE 1 1 1 1 2 2 22 1 3 3 33 1 4 3 333 1 I also want that contract 1
So basically I want all contracts, but if all contracts were duplicated (2 or 3 lines), I wanted to choose only the customers that has the matching condition in another table.
Something like this should work:
WITH account as
(SELECT t1.*, COUNT (*) (PARTITION BY contract) c FROM table1 t1)
SELECT * FROM account c
WHERE c = 1
OR EXISTS (SELECT 1 from table2 WHERE customer = c.customer AND type_code = "E-MAIL address"); -
SQL query to get the NULL records after the last matching flag
I have a xx1 table with id and flag columns. So I want the data in this table, after the last flag matched. I want that data to id 7 in the rooms. Even if the id 2,3,5 are null flag 'Y' was at 6. ID so I need a query to get the data of the xx1 table after the last correspondence flag (from 7 to 9 id).
SQL > create table xx1
2 (identification number,
3 flag varchar2 (10));
Table created.
SQL > insert into xx1 values (1, 'Y');
1 line of creation.
SQL > insert into values xx1 (2, null);
1 line of creation.
SQL > insert into values xx1 (3, null);
1 line of creation.
SQL > insert into xx1 values (4, 'Y');
1 line of creation.
SQL > insert into values xx1 (5, null);
1 line of creation.
SQL > insert into xx1 values (6, 'Y');
1 line of creation.
SQL > insert into values xx1 (7, null);
1 line of creation.
SQL > insert into values xx1 (8, null);
1 line of creation.
SQL > insert into values xx1 (9, null);
1 line of creation.
SQL > select * from xx1.
FLAG OF THE ID
---------- ----------
1. IS
2
3
4. IS
5
6. IS
7
8
9
9 selected lines.
SQL >
Hello
user11164339 wrote:
Hi Frank - when I run the query, I don't see the results data.
I get
FLAG OF THE ID
----- ----------
7
8
9
What you do differently?
-
SQL query to get the items for which transactions have not been saved
Hi people,
Have a small doubt I want to compile a SQL query in the inventory where I get these items for what transactions do not have been recorded during a period of at least one specified number of days.
The days might be 30 days or 2 months depends on. If I want to get those items for which no transactions were reported for lets say 30 days. Could someone give me an idea of how to go about this thing? I use r12. I came up with the following query, but it gives a lot of records. The commented parts of this query is only commented on
SELECT DISTINCT msi.segment1,
MSI. Description,
MSI.primary_uom_code,
MSI.inventory_item_id
MSI mtl_system_items_b / *,.
mtl_material_transactions mmt * /.
WHERE / * msi.inventory_item_id = mmt.inventory_item_id
AND msi.organization_id = mmt.organization_id
AND NVL ((SELECT SUM (transaction_quantity)
OF mtl_onhand_quantities
WHERE inventory_item_id = msi.inventory_item_id),
0) = 0
AND TRUNC (mmt.transaction_date) < = SYSDATE - & D
AND * / NOT EXISTS (SELECT *)
OF mtl_material_transactions mmt
WHERE msi.inventory_item_id = mmt.inventory_item_id
AND msi.organization_id = mmt.organization_id
AND TRUNC (mmt.transaction_date) < SYSDATE - & D);
Hi fatimakhellil
Try the following code and mark it as correct if your problem be resolved.
SELECT DISTINCT msi.segment1,
MSI. Description,
MSI.primary_uom_code,
MSI.inventory_item_id,
MSI.organization_id,
Ms.secondary_inventory_name,
(select max (transaction_date) in the mtl_material_transactions where msi.inventory_item_id = inventory_item_id
AND msi.organization_id = organization_id) last_transaction_date
OF mtl_system_items_b msi.
Ms. mtl_secondary_inventories
WHERE ms.organization_id (+) = msi.organization_id
AND msi.source_subinventory = ms.secondary_inventory_name (+)
AND NOT EXISTS (SELECT *)
OF mtl_material_transactions mmt
WHERE msi.inventory_item_id = mmt.inventory_item_id
AND msi.organization_id = mmt.organization_id
AND mmt.subinventory_code = ms.secondary_inventory_name
AND mmt.organization_id = ms.organization_id
AND TRUNC (mmt.transaction_date) BETWEEN TRUNC (SYSDATE - & d) AND TRUNC (SYSDATE))
-
Need a sql query to get several dates in rows
Hi all
I need a query to get the dates of the last 7 days and each dates must be in a line...
but select sysdate double... gives a line...
Output of expexcted
Dates:
October 1, 2013
30 sep-2013
29 sep-2013
28 sep-2013
27 sep-2013
26 sep-2013
Try:
SQL > SELECT sysdate-7 + LEVEL FROM DUAL
2. CONNECT BY LEVEL<=>=>
3 * ORDER BY 1 DESC
SQL > /.
SYSDATE-LEVEL 7 +.
-----------------------------
October 1, 2013 13:04:52
30 - Sep - 2013 13:04:52
29 - Sep - 2013 13:04:52
28 - Sep - 2013 13:04:52
27 - Sep - 2013 13:04:52
26 - Sep - 2013 13:04:52
25 - Sep - 2013 13:04:52
7 selected lines.
-
IOM sql Query to get the status of the failed task
Hello world
We have an obligation as we need to get the status of a particular task (say Create User in OID - Completed\Rejected status resource) for the particular user. We are able to get the status of the provisioed of resources to the user but not the status of the special mission which is trigerred for the user.can someone put some light on it. We must have the SQL query to do this.
Thanks in advance.
Kind regards
MKNHello
Use this query to get the status of the task, also check the coomentsSELECT USR. USR_LOGIN, OSI. SCH_KEY, ANN. SCH_STATUS, STA. STA_BUCKET OF
OSI, CHS, STA, MIL, TOS, PKG, OUEDRAOGO, USR, OBJ, OST
WHERE OSI.MIL_KEY = MIL.MIL_KEY
AND ANN. SCH_KEY = OSI. SCH_KEY
AND STA. STA_STATUS = SCH. SCH_STATUS
AND TOS. PKG_KEY = PKG. PKG_KEY
AND MIL. TOS_KEY = TOS. TOS_KEY
AND OUÉDRAOGO. USR_KEY = USR. USR_KEY
AND OUÉDRAOGO. OST_KEY = OST. OST_KEY
AND OST. OBJ_KEY = OBJ. OBJ_KEY
AND OSI. ORC_KEY = OUEDRAOGO. ORC_KEY
AND OBJ. OBJ_NAME = "User AD".
AND OST. OST_STATUS = "Provisioning" - filter accordinglly
AND STA. STA_BUCKET = 'pending' - filter accordinglly
AND PKG. PKG_NAME = "AD User" - filter accordinglly
AND MIL.MIL_NAME = 'System' - filter accordinglly Validation
;
Thank you
Kuldeep -
SQL query to a / columns of values for all the rows that are returned by default
Hello everyone.
I was looking for help to make an SQL query that can be achieved if all goes well-
I want that all the rank values in a particular column of a set of rows returned by default for a specified string. For example, consider the SQL below:
Select date, start_time, building and room
of star.events
Consider this example output of the query above-
Start_time date room
2009-07-01 9: 00 AB 99
2009-02-03 7:11 ED
2009-01-03 8:23 FF
2009-03-04 4 am SD 29
How can I change my statement default SQL column space to say ' 57 "regardless of what the actual database values are showing this instead?
Start_time date room
01/07/2009 9:57 AB
2009-02-03 7:57 ED
03/01/2009 8:57 FF
2009-03-04 4 am JJ 57
Any direction/suggestions would be much appreciated.
Thank you!Hello
SELECT DATE, start_time, building, 57 as room FROM star.events;
Kind regards
-
Query to get the previous value
Hello guys,.
I have a problem to do a simple Oracle's SQL query.
I will give an example. Imagine a table (test) with the following data:
DATE DEPRECIATION AMORTIZATION
-----------------------------------------------------------------------------------------------
01/01/2013 1.00 1.00
02/05/2013 1.00 2.00
03/08/2013 1.00 3.00
04/12/2013 1.50 4.50
13/05/2013 1,00 5.50
22/06/2013 1,00 6.50
17/07/2013 1,00 7.50
08/11/2013 1.00 8.50
27/09/2013 1,00 9.50
10/01/2013 0.50 10.0
11/01/2013 1,00 12.0
12/01/2013 1.00-13.0
If I want to recover the accumulated depreciation from June to December, is simple:
SELECT DEPRECIATION
OF THE TEST
WHERE DATE BETWEEN to_date ('01-06-2013 ',' DD - MM - yyyy")
AND to_date ('01-12-2013 ',' DD - MM - yyyy")
However, I would like to create a field that question to bring the accumulated depreciation of the
previous month (month of May), without changing the WHERE clause. Where I work, we use views to make such a request, but the performance is terrible.
Anyone know the solution to this problem or can offer some advice?
1f7629cd-28fe-4FC3-9CA0-2a2e51824e79 wrote:
Solomon, this is the result I want. However, in a dynamic way.
I don't have a need to communicate their data.
I think you speak WITH clause. You don't commit CREATE TABLE + INSERT, WITH the clause is a quick way to create your table on the fly. All you need is:
Select t.*,
accumulated_deprecation - prev_mon_accum_deprecation deprecation
t
where dt between to_date('01-06-2013','dd-MM-yyyy') and to_date('01-12-2013','dd-MM-yyyy')
/
Of course, you must change the table names and column in your names. I don't know what happened to your last post, but on this basis:
SELECT m.dat_mov_patr,
m.val_valor_real,
m.val_depr_acumulada,
m.val_depr_acumulada - m.val_valor_real
OF mov_patrimonial m
WHERE m.dat_mov_patr > to_date (January 3, 2005 ', "dd-MM-yyyy")
/
And it's all simple arithmetic - no need to use all functions. Column val_depr_acumulada accumulated disapproval of the month 1 to the current month. Column val_valor_real is the disapproval of the current month. Val_depr_acumulada - val_valor_real is therefore accumulated disapproval of the month 1 month.
SY.
-
Database SQL query to get all virtual machines with comments enabled customization?
Hello
Does anyone know of a SQL query that can be executed against the vCloud Director DB for all virtual machines who invited enabled customization?
I can't have PowerShell to pull these data on a global scale.
Thank you
jkasal
Has taken a quick...
Select top 10 v.id, v.name, v.vapp_name, v.vc_id, v.moref, ui_vapp_vm_list_view v.guest_customize_enabled v with (NOLOCK)
seems to have if the setting is enabled or not.
-
Need for SQL query to get the result.
Region
Month Trx type Summary of the resolution AMERICAS -13 may Adjustments Fix EMEA -13 may Adjustments Incorrect AMERICAS -13 may Credit memo Incorrect EMEA -13 may Invoice Fix AMERICAS -13 may Credit memo Fix OFD -13 may Adjustments Fix AMERICAS -13 may Invoice Incorrect DVL -13 may Adjustments Fix DVL -13 may Adjustments Fix OFD -13 may Adjustments Fix Above my Table and here is the result required. Similarly for other regions as well. Can someone help me with the SQL query?
Region Summary of the resolution Setting Credit memo Invoice Total general AMERICAS Fix 1 1 2 Incorrect 0 1 1 2 Like this?
SQL > select * from transaction_audit;
MTH TRX_TYPE REGION BOARD
-------- ------ ----------- ---------
AMERICAS-13 may SETTINGS CORRECT
EMEA-13 may INCORRECT ADJUSTMENT
AMERICAS-13 may CREDIT MEMO INCORRECT
EMEA-13 may INVOICE CORRECT
AMERICAS-13 may CREDIT MEMO CORRECT
OFD-13 may SETTINGS CORRECT
AMERICAS-13 may INVOICE INCORRECTE
LAD-13 may SETTINGS CORRECT
LAD-13 may SETTINGS CORRECT
OFD-13 may SETTINGS CORRECT10 selected lines.
SQL > select region
2, resolution_summary
3, count (decode (trx_type, "ADJUSTMENTS", trx_type)) adjustments
4, County (decode (trx_type, 'HAVING', trx_type)) credit_memo
5, County (decode (trx_type, "BILL", trx_type)) Bill
transaction_audit 6
Group 7
8 by region
9, resolution_summary
10 Decree
11 by region
12, resolution_summary
13.REGION TAKE ADJUSTMENTS CREDIT_MEMO INVOICE
-------- --------- ----------- ----------- ----------
CORRECT THE AMERICAS 1 1 0
0 1 1 INCORRECT AMERICAS
EMEA CORRECT 0 0 1
INCORRECT EMEA 1 0 0
DAL ADDRESS 2 0 0
OFD CORRECT 2 0 06 selected lines.
SQL >
-
I want to clarify 3 ranges as breeders of the case. For example, I am able mV and I want 0.10, 10.20 and 20.30, but, when I enter them in this way, I get an error that says that the selection values are not unique.
I want case to answer when the input is greater than 0 but less than 10.
I want the second case to react when the input is greater than 10, but less than 20.
I want the third case to react when the input is higher than 20, but less than 30.
And there is the case by default, 0. The case structure think my default is bunk with my case? How a list correctly these ranges in the Tag Chooser structure cases to avoid the error?
Also, I plugged in my blood "to LONG integer" and then to the Terminal case structure to convert entire for the entry of case structure (blue wire). Is it the right thing to do, because my values of tension will certainly be decimal numbers, not integers.
Before converting in I32, for example, use "turn to + inf" and settle the case accordingly.
(A plain to_I32 rounds to the nearest integer, making it impossible to meet limits).
Maybe you are looking for
-
Satellite P100 - Win XP PRO - unable to connect to normal - WLAN card
Cannot connect in normal mode, Windows XP Pro Satellite P100. I can only access my PC under XP in safe mode.I have my Windows password. What happened: I tried to update my network card drivers and I put access to check the connection. I can't update
-
PlayMemories Mobile/Smart Remote - no video recording! Why Sony Action Cam it allows?
Just bought a NEX-6. The Smart Remote application is the reason why I bought the camera in the hope that, with a future update to the app NEX-6 and 5R can not only turn the trigger but also switch VIDEO! Currently, even when the Smart remote control
-
Hello I have important files that have photos and others that are punch and would keep without having to make a backup of them some how.
-
File Association message when you try to run the Windows 7 upgrade
I'm eager to start the download for Win7 upgrade of Vista. My Download Manager tells me it's done as a .iso file. When I try to start I get a message the file Association that frankly confuses me. What should I do to get the thing running? Thank you,
-
How do CabArc or record MakeCab strings in unicode format
Hello, I'm unable to make an archive of files, whose names must be in unicode format. I'm following on to the task of making the actual cab file, but after extraction, some of the characters used in the file names are replaced with characters from th