Select query-using Union All display duplicate records.
Hello All Gurus-
I am using Oracle 9.i
When i use the following query to fetch the records based on BUILDNUMBERNAME and ASSIGNED_BUILD then i am getting duplicate records -
select T1.ID FROM Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1. ASSIGNED_BUILD like '1.4.5.6'
Union All
select T1.ID FROM Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1.BUILDNUMBERNAME like '1.4.5.6'
How can i use the order by on T1.ID ? When i use the Order by T1.ID then it throws some error.
Kindly help me in this :(
Thanks in advance.
Sorry for not providing all of the details -
I am using Toad tool to run the query.
1-When i use the following query -
Select T1.ID FROM Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1. ASSIGNED_BUILD like '1.4.5.6' order by T1.ID
Union All
select T1.ID FROM Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1.BUILDNUMBERNAME like '1.4.5.6' order by T1.ID
ORA-00933: SQL command not properly ended.
2-If i am not using the T1.ID and run the following query
Select T1.ID FROM Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1. ASSIGNED_BUILD like '1.4.5.6'
Union All
select T1.ID FROM Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1.BUILDNUMBERNAME like '1.4.5.6'
Then it is running fine but it is displaying the duplicate values like -
00089646
00087780
00089148
00090118
00090410
00088503
00080985
00084526
00087108
00087109
00087117
00088778
00086714
00079518
00087780
00089148
00090392
00090393
00090395
00090398
00090401
00090402
00090403
00090406
00090408
00088503
00080985
00084526
00087108
00087109
00087117
00088778
00086714
00079518
Similar Messages
-
Query using Union All and CTEs is slow
TypePatient
[ednum] int NOT NULL, PK
[BackgroundID] int NOT NULL, FK
[Patient_No] varchar(50) NULL, FK
[Last_Name] varchar(30) NULL,
[First_Name] varchar(30) NULL,
[ADateTime] datetime NULL,
Treat
[ID] int NOT NULL, PK
[Ednum] numeric(10, 0) NOT NULL, FK
[Doctor] char(50) NULL,
[Dr_ID] numeric(10, 0) NULL,
background
[ID] int NOT NULL, PK
[Patient_No] varchar(50) NULL, FK
[Last_Name] char(30) NULL,
[First_Name] char(30) NULL,
[DateofBirth] datetime NULL,
pdiagnose
[ID] int NOT NULL, PK
[Ednum] int NOT NULL, FK
[DSMNo] char(10) NULL,
[DSMNoIndex] char(5) NULL,
substance
[ID] int NOT NULL, PK
[Ednum] int NOT NULL, FK
[Substance] varchar(120) NULL,
DXCAT
[id] int NULL, PK
[dx_description] char(100) NULL,
[dx_code] char(10) NULL,
[dx_category_description] char(100) NULL,
[diagnosis_category_code] char(10) NULL)
Substance
ID
Ednum
Substance
1
100
Alcohol Dependence
4
200
Caffeine Dependence
5
210
Cigarettes
dxcat
id
dx_description
dx_code
dx_category_description
diagnosis_category_code
10
Tipsy
zzz
Alcohol
SA
20
Mellow
ppp
Mary Jane
SA
30
Spacey
fff
LSD
SA
50
Smoker
ggg
Nicotine
SA
pdiagnose
ID
Ednum
DSMNo
Diagnosis
1
100
zzz
Alcohol
2
100
ddd
Caffeine
3
210
ggg
Smoker
4
130
ppp
Mary Jane
TypePatient
ednum
Patient_No
Last_Name
First_Name
ADateTime
100
sssstttt
Wolly
Polly
12/4/2013
130
rrrrqqqq
Jolly
Molly
12/8/2013
200
bbbbcccc
Wop
Doo
12/12/2013
210
vvvvwww
Jazz
Razz
12/14/2013
Treat
ID
Ednum
Doctor
Dr_ID
2500
100
Welby, Marcus
1000
2550
200
Welby, Marcus
1000
3000
210
Welby, Marcus
1000
3050
130
Welby, Marcus
1000
background
ID
Patient_No
Last_Name
First_Name
DateofBirth
2
sssstttt
Wolly
Polly
8/6/1974
3
rrrrqqqq
Jolly
Molly
3/10/1987
5
bbbbcccc
Wop
Doo
8/12/1957
6
vvvvwww
Jazz
Razz
7/16/1995
Desired output:
Staff ID
Doctor
Patient_No
Client Name
Date of Service
Ednum
DX Code
DX Cat
DX Desc
Substance
1000
Welby, Marcus
bbbcccc
Wop, Doo
12/12/2013
200
Caffeine Dependence
1000
Welby, Marcus
rrrqqq
Jolly, Molly
12/8/2013
130
ppp
SA
Mary Jane
1000
Welby, Marcus
sssttt
Wolly, Polly
12/4/2013
100
zzz
SA
Alcohol
1000
Welby, Marcus
sssttt
Wolly, Polly
12/4/2013
100
ddd
SA
LSD
1000
Welby, Marcus
sssttt
Wolly, Polly
12/4/2013
100
Alcohol Dependence
1000
Welby, Marcus
vvvvwww
Jazz, Razz
12/14/2013
210
ggg
SA
Smoker
1000
Welby, Marcus
vvvvwww
Jazz, Razz
12/14/2013
210
Cigarettes
A patient is assigned an ednum. There are two different menus for staff to enter
diagnoses. Each menu stores the entries in a different table. The two tables are substance and pdiagnose. A patient’s diagnosis for a substance abuse can be entered in one table and not the other.
The number of entries for different substances for each patient can vary between the two tables. John Doe might be entered for alcohol and caffeine abuse in the pdiagnosis table and entered only for caffeine abuse in the substance table. They are only
linked by the ednum which has nothing to do with the diagnosis/substance. The substance entered in one table is not linked to the substance entered in the other. A query will not put an entry for alcohol from the pdiagnosis table on the same row as an alcohol
entry from the substance table except by chance. That is the reason for the way the query is written.
The query accepts parameters for a Dr ID and a start and end date. It takes about 7 to 15 seconds to run. Hard coding the dates cuts it down to about a second.
I might be able to select directly from the union all query instead of having it separate. But then I’m not sure about the order by clauses using aliases.
Is there a way to rewrite the query to speed it up?
I did not design the tables or come up with the process of entering diagnoses. It can’t be changed at this time.
Please let me know if you notice any inconsistencies between the DDLs, data, and output. I did a lot of editing.
Thanks for any suggestions.
with cte_dxcat (Dr_ID, Doctor, Patient_No,Last_Name,
First_Name, Adatetime,Ednum,
dx_code,diagnosis_category_code,dx_description,substance,
DateofBirth) as
(Select distinct t.Dr_ID, t.Doctor, TP.Patient_No,TP.Last_Name,
TP.First_Name, TP.Adatetime as 'Date of Service',TP.Ednum,
DXCAT.dx_code,DXCAT.diagnosis_category_code,DXCAT.dx_description,
null as 'substance',BG.DateofBirth
From TypePatient TP
inner join treat t on TP.ednum = t.Ednum
inner join background BG on BG.Patient_No = TP.Patient_No
inner join pdiagnose PD on TP.Ednum = PD.Ednum
inner join Live_Knowledge.dbo.VA_DX_CAT_MAPPING DXCAT on DXCAT.dx_code = PD.DSMNo
Where (TP.Adatetime >= convert(varchar(10), :ST, 121)+ ' 00:00:00.000'
and TP.Adatetime <= convert(varchar(10), :SP, 121)+ ' 23:59:59.000')
and DXCAT.diagnosis_category_code = 'SA'
and t.Dr_ID =:DBLookupComboBox2
cte_substance (Dr_ID, Doctor, Patient_No,Last_Name,
First_Name,Adatetime, Ednum,
dx_code,diagnosis_category_code,dx_description,Substance,DateofBirth) as
(Select distinct t.Dr_ID, t.Doctor, TP.Patient_No,TP.Last_Name,
TP.First_Name, TP.Adatetime as 'Date of Service', TP.Ednum,
null as 'dx_code',null as 'diagnosis_category_code',null as 'dx_description',s.Substance, BG.DateofBirth
From TypePatient TP
inner join treat t on TP.ednum = t.Ednum
inner join background BG on BG.Patient_No = TP.Patient_No
inner join pdiagnose PD on TP.Ednum = PD.Ednum
inner join substance s on TP.Ednum = s.Ednum
Where (TP.Adatetime >= convert(varchar(10), '12/1/2013', 121)+ ' 00:00:00.000'
and TP.Adatetime <= convert(varchar(10), '12/31/2013', 121)+ ' 23:59:59.000')
and t.Dr_ID =:DBLookupComboBox2
cte_all (Dr_ID, Doctor, Patient_No,Last_Name,
First_Name,Adatetime, Ednum,
dx_code,diagnosis_category_code,dx_description,Substance,DateofBirth) as
(select cte_dxcat.Dr_ID as 'Staff ID', cte_dxcat.Doctor as 'Doctor',
cte_dxcat.Patient_No as 'Patient_No',
cte_dxcat.Last_Name as 'Last',cte_dxcat.First_Name as 'First',
cte_dxcat.Adatetime as 'Date of Service',cte_dxcat.Ednum as 'Ednum',
cte_dxcat.dx_code as 'DX Code',cte_dxcat.diagnosis_category_code as 'DX Category Code',
cte_dxcat.dx_description as 'DX Description',
cte_dxcat.substance as 'Substance',cte_dxcat.DateofBirth as 'DOB'
from cte_dxcat
union all
select cte_substance.Dr_ID as 'Staff ID', cte_substance.Doctor as 'Doctor',
cte_substance.Patient_No as 'Patient_No',
cte_substance.Last_Name as 'Last',cte_substance.First_Name as 'First',
cte_substance.Adatetime as 'Date of Service',cte_substance.Ednum as 'Ednum',
cte_substance.dx_code as 'DX Code',cte_substance.diagnosis_category_code as 'DX Category Code',
cte_substance.dx_description as 'DX Description',
cte_substance.substance as 'Substance',cte_substance.DateofBirth as 'DOB'
from cte_substance)
select cte_all.Dr_ID as 'Staff ID', cte_all.Doctor as 'Doctor',
cte_all.Patient_No as 'Patient_No',
(cte_all.Last_Name + ', '+ cte_all.First_Name) as 'Client Name',
cte_all.Adatetime as 'Date of Service',cte_all.Ednum as 'Ednum',
cte_all.dx_code as 'DX Code',cte_all.diagnosis_category_code as 'DX Category Code',
cte_all.dx_description as 'DX Description',
cte_all.substance as 'Substance',
CONVERT(char(10), cte_all.DateofBirth,101) as 'DOB'
from cte_all
order by cte_all.Patient_No,cte_all.AdatetimePlease post real DDL instead of your invented non-language, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions
and formatting rules. Your rude, non-SQL narrative is so far away from standards I cannot even use you as a bad example in book.
Temporal data should use ISO-8601 formats (we have to re-type the dialect you used!). Code should be in Standard SQL as much as possible and not local dialecT.
This is minimal polite behavior on SQL forums. You posted a total mess! Do you really have patients without names?? You really use a zero to fifty characters for a patient_nbr??? Give me an example. That is insane!
Your disaster has more NULLs than entire major corporate systems. Since you cannot change it, can you quit? I am serious. I have been employed in IT since 1965, and can see a meltdown.
I looked at this and I am not even going to try to help you; it is not worth it. I am sorry for you; you are in an environment where you cannot learn to do any right.
But you are still responsible for the rudeness of not posting DDL.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Cannot export query output when using UNION ALL
Hi
I can run a query in SQL Developer 1.5.5 and if it's a SELECT statement it works fine, but if I output the result of several SELECT statements using UNION ALL after some 10,000 records the SQL Developer crashes and it generates a file whose size is 0 kb
Is there a workaround for this??
Thanks and Regards!
IsaacShould be fixed in the upcoming 2.1... you can try the RC1 also...
Regards,
K. -
Need sql query to remove duplicates using UNION ALL clause
Hi,
I have a sql query which has UNION clause.But the UNION clause is causing some performance issues.
To overcome that I have used UNION ALL to improve performance but its returning duplicates.
Kindly anyone send a sample SQL query where my primary objective is used to use UNION ALL clause and to consider unique rows (elimating duplicate
ones)
Any help will be needful for me
Thanks and Regardswhy not UNION? :(
another way also use MINUS
SQL>
SQL> with t as
2 (
3 select 1 if from dual union all
4 select 2 if from dual union all
5 select 1 if from dual union all
6 select 3 if from dual union all
7 select 3 if from dual
8 )
9 ,t2 as
10 (
11 select 1 if from dual union all
12 select 2 if from dual union all
13 select 3 if from dual union all
14 select 4 if from dual union all
15 select 5 if from dual
16 )
17 (select if from t
18 union all
19 select if from t2)
20 /
IF
1
2
1
3
3
1
2
3
4
5
10 rows selected
SQL> so
SQL>
SQL> with t as
2 (
3 select 1 if from dual union all
4 select 2 if from dual union all
5 select 1 if from dual union all
6 select 3 if from dual union all
7 select 3 if from dual
8 )
9 ,t2 as
10 (
11 select 1 if from dual union all
12 select 2 if from dual union all
13 select 3 if from dual union all
14 select 4 if from dual union all
15 select 5 if from dual
16 )
17 (select if from t
18 union all
19 select if from t2)
20 minus
21 select -99 from dual
22 /
IF
1
2
3
4
5
SQL> -
Avoid displaying duplicates records?
I have the following query to display records from two tables:
select * from COLLATERAL CL, COLLATERAL_REF CF where CF.ACCOUNT_NUMBER like '1000000001%' AND CF.COLLATERAL_ID=CL.COLLATERAL_ID
How do i change this query to avoid duplicate collateral_id's?.
Collateral_id is the primary key on Collateral table and foreign key on Collateral_ref table.
nullThanks isotope for your reply.
I just ran the query and I get 00904:"cl"."collateral_id": invalid identifier.
Here is my table structure:
Collateral (Collateral_id is Primary Key):
Collateral_id Collateral_type Description Serial_Number ..
1 Title 97 Accord 111111
32 Mortgage 122 Grand Av
26 Title 2008 BMW 222222
Collateral_Ref (Collateral_id is foreign key)
Collateral_id Account_Number Description ..
1 100000001 111111111 97 Accord
1 100000001 222222222 97 Accord
32 100000001 444444444 122 Grand Av
32 100000001 333333333 122 Grand Av
32 100000001 999999999 122 Grand Av
26 200000001 222222222 2008 BMW
So, My query currently returns all the duplicate (1 twice and 32 thrice)
expected results should be:
Collateral_id Collateral_type Description ..
1 Title 97 Accord
32 Mortgage 122 Grand Av -
Hello again.
Another question.
Can I query with union all and stop it when I get N rows.
For example:
select 1 from dba_segments
union all
select 2 from dba_segments where
union all
select 3 from dba_segments where;
and get the 100 first rows without doing the whole query:(not like that-->)
select * from (
select 1 from dba_segments
union all
select 2 from dba_segments where
union all
select 3 from dba_segments where)
where rownum < 100);
I want the query will stop when there are 100 rows in the result set.
thank you!You already posted your own answer. It just seems you don't want to use it.
ROWNUM is NOT assigned until the rows are selected to be returned. So you need to wrap the three inner queries into a query that uses ROWNUM. -
Hello
i have 2 schemas S1 and S2 containing complex relational tables. The tables in each schema are related to each other via foreign key relationships. i made views for feature tables in both the schemas , querying column values from their related tables.
the data structure in both the schemas are exactly the same. Dut to management reasons we have to split them in 2 schemas. S1 contain data for region A and S2 contains data from region B. Now the client wants to see a combined data from region A & B.
we are planning to create another schema S3 and make views combining views from S1 and S2 in both schemas (V1 in S1 + V1 in S2) using UNION ALL.
Does UNION ALL will make use of the indexes we already built for parent tables in S1 and S2? Will there be a performance degradation using this approach? What can be the best approach? Our client needs to see real time data....
regards
samSince union does an extra sort it has a performance difference compared to union all.
SQL> select user from dual union select user from dual ;
USER
HR
SQL> select user from dual union all select user from dual ;
USER
HR
HRİf there is up to date and appropriate object statistics Oracle's Cost Based Optimizer will choose best access path, join method and join order depending on your query. Only exceptions are hints, outlines and sql profiles since they stabilize the execution plan.
For further commenting please post your oracle version, query's test results and its statistics taken from sql*plus timing and autotrace options - http://www.bhatipoglu.com/entry/17/oracle-performance-analysis-tracing-and-performance-evaluation -
Drill down problem when using union all combination
Hi All,
I have a simple report with a drill down. The report has three columns Region, Sales, Flag... which will drill down to detail level of sales. The Flag column has Y, N values and we added 'All' Value in flag so that the user can select Y, N and All from the table prompt in the report . We have used union all in the report using combination to add the ' All ' Value in the flag. The problem is that now the main report is not passing the Flag values to the detail report. Flag is prompted in the filter in detail report.
If I remove the 'All' value from Analysis with only Y N selection criteria the drill down works.
Is there any work around? I have to use table prompt and All value selection in flag for drill down.
Thanks,
ViratThe problem is without union all when doing combination of analysis drill down works, when I use combination drill down does not work because it does not pass the parameters for flag . I have used union all to add All value in flag.
-
Hi,
Please give me the Select query
I have to fetch EBELN,BUKRS,LIFNR,BSART,EKORG,EKGRP,WAERS,WKURS from EKKO and
EBELP,LGORT,MATKL ,WERKS,BEDNR,IDNLF,BPRME,NETPR from EKPO and
MENGE, SAKTO,AUFNR,ANLN1,GSBER,PS_PSP_PNR from EKKN and
LPEIN,EINDT,SLFDT, from EKET.
I have to fetch all the data into an single internal table(Mandatory) by a select query using Joins.
EKKO is having EBELN as primary key
EKPO is having EBELN,EBELP as primary key
EKKN is having EBELN,EBELP as primary key
EKET is having EBELN,EBELP as primary key
Can anybody Please give me the Select query.
With Regards
AjayHi ,
I am sending this sample coed for the Inner joins .Hope this will help you:
Inner joins using 3 tables
Try this :-
SELECT stpostlnr stpoidnrk mastmatnr maramtart stpo~menge
INTO CORRESPONDING FIELDS OF TABLE zmat1 FROM mast
JOIN stpo ON stpostlnr = maststlnr
JOIN mara ON maramatnr = mastmatnr
WHERE stpostlty = 'M' "AND stpoidnrk IN s_matnr
AND mast~werks = 1000.
Here s_matnr is a select-options on the selection-screen.
Or this.
Code:
Select single VbrkBukrs VbrkKunrg Vbrk~Vbeln
VbrkFkdat VbrkBstnk_Vf Vbrk~Zterm
Tvzbt~Vtext
VbakVbeln VbakBstdk
LikpVbeln Likplfdat Likp~Lfuhr
into w_vbrk
from vbrk
inner join Tvzbt on TvzbtZterm = VbrkZterm and
Tvzbt~Spras = sy-langu
Inner join Vbfa as SalesLnk
on SalesLnk~vbeln = pu_vbeln and
SalesLnk~vbtyp_v = c_order
inner join Vbak on VbakVbeln = SalesLnkVbelv
Inner join Vbfa as DeliveryLnk
on DeliveryLnk~vbeln = pu_vbeln and
DeliveryLnk~vbtyp_v = c_Delivery
inner join Likp on LikpVbeln = DeliveryLnkVbelv
where vbrk~vbeln = pu_Vbeln.
This code locates sales, delivery and payment terms info from a billing document number.
or
Here, this one also works fine :
select zfpcdcadivi zfpcdproforma zfpcdfactura zfpcdaniofactura
zfpcdmontousd zfpcdmontoap zfpcdebeln zfpcdinco1
zfpcdlifnr lfa1name1 zcdvsstatus zfpcdconint
into it_lista
from zfpcd inner join zcdvs
on zfpcdebeln = zcdvsebeln
and zfpcdproforma = zcdvsproforma
and zfpcdlifnr = zcdvslifnr
inner join lfa1
on zfpcdlifnr = lfa1lifnr
where zcdvs~status = '04'.
Also Here is another solution that just uses inner joins:
SELECT vbakvbeln vbfaerdat INTO (itab-vbeln, itab-wadat)
FROM ( vbak INNER JOIN vbap
ON vbapvbeln = vbakvbeln )
INNER JOIN vbfa ON vbakvbeln = vbfavbelv
WHERE vbak~kunnr = m_wm AND
vbak~vbtyp = 'C' AND
vbfa~erdat IN s_date AND
vbap~matnr = 'MZ1807F' AND
vbfaposnv = vbapposnr AND
vbfa~vbtyp_n = 'J'.
<REMOVED BY MODERATOR>
Cheers,
Chandra Sekhar.
Edited by: Alvaro Tejada Galindo on Apr 10, 2008 5:20 PM -
How to run select query from one SID to fetch record from another SID?
I have two SID, one is AAA and another is BBB and the connection name is A1 and B1 respectively. I want to run one select query from A1 connection to fetch record B1. Can anyone help me how I can connect from one SID to another SID?
Hi 869357,
You can also use the copy command. (Works with limited types)
try:
help copyRegards,
Turloch -
Select extra row without using UNION ALL in pl/sql
Hi,
Can anyone tell me how to select extra row without using UNION or UNION ALL in pl/sql. Actually I want to have my o/p of query as partitioned by designation and ordered by salary and than one extra row which will contain the highest salary in a particular salary. My table has first_name,emp_id,designation and salary column. And I wnt the o/p as.
Mohinish,12212,SI,46000
Ram,11212,SSI,47000
Shyam,12133,SI,48000
Rick,9898,SI,46000
Rocky,12312,SSI,56000
Sariq,23948,SI,43000
Suman,12789,HR,49000
Sampy,12780,SI,46000
Parna,11111,HR,50000
Now the o/p should be.
Mohinish,12212,SI,46000
Rick,9898,SI,46000
Sariq,23948,SI,43000
Shyam,12133,SI,48000
Shyam,12133,SI,48000
Ram,11212,SSI,47000
Rocky,12312,SSI,56000
Rocky,12312,SSI,56000
Suman,12789,HR,49000
Parna,11111,HR,50000
Parna,11111,HR,50000
Thanks in AdvanceYou don't have to do a UNION or UNION ALL in PL/SQL but you would need to in SQL to get the desired output:
with data_recs
as (select 'Mohinish' first_name,12212 emp_id,'SI' designation,46000 salary from dual union
select 'Ram',11212,'SSI',47000 from dual union
select 'Shyam',12133,'SI',48000 from dual union
select 'Rick',9898,'SI',46000 from dual union
select 'Rocky',12312,'SSI',56000 from dual union
select 'Sariq',23948,'SI',43000 from dual union
select 'Suman',12789,'HR',49000 from dual union
select 'Sampy',12780,'SI',46000 from dual union
select 'Parna',11111,'HR',50000 from dual)
select first_name, emp_id, designation, salary from data_recs union all
select s.first_name, s.emp_id, s.designation, s.salary
from (select first_name,
emp_id,
designation,
salary,
row_number() over (partition by designation order by salary desc) high_salary
from data_recs
order by designation, salary) s
where s.high_salary = 1
order by designation, salary;
FIRST_NAME EMP_ID DESIGNATION SALARY
Suman 12789 HR 49000
Parna 11111 HR 50000
Parna 11111 HR 50000
Sariq 23948 SI 43000
Rick 9898 SI 46000
Mohinish 12212 SI 46000
Sampy 12780 SI 46000
Shyam 12133 SI 48000
Shyam 12133 SI 48000
Ram 11212 SSI 47000
Rocky 12312 SSI 56000
Rocky 12312 SSI 56000 -
Query displaying duplicate records
I have written a query to display materials having no purchasing group.
Can any one plz tell me that why it is displaying duplicate results.
Thanks
aprrApprr,
You have given us no information to help you.
Please list the Datasource: Table Join, Direct Read, Logical database, or program.
Please list any Table or Tables you are using.
If you are using Table join(s), please list the joined tables and all linking fields.
Rgds,
DB49 -
Trying to create table using Union All Clause with multiple Select stmts
The purpose of the query is to get the Substring from the value for eg.
if the value is *2 ASA* then it should come as ASA
where as if the value is *1.5 TST* the it sholud come as TST like wise for others too.
I am trying to execute the below written SQL stmt but getting error as:
*"ORA-00998 must name this expression with the column alias 00998.00000 - Must name this expression with the column alias"*
CREATE TABLE TEST_CARE AS
SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
WHERE LENGTH(old_care_lvl) =5
UNION ALL
SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
WHERE LENGTH(old_care_lvl) =7
UNION ALL
SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
WHERE LENGTH(old_care_lvl) =14
UNION ALL
SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3),LEN FROM test_care_lvl
WHERE LENGTH(old_care_lvl) =7 AND old_care_lvl ='Regular'
I want to create the table using the above given multiple select using the Union ALL clause but when trying to create run the query getting error as "ORA-00998 must name this expression with the column alias 00998.00000 - Must name this expression with the column alias"
Please guide me how to approach to resolve this problem.
Thanks in advance.When you create a table using a SELECT statement the column names are derived from the SELECT list.
Your problem is that one of your columns is an expression that does not work as a column name SUBSTR(old_care_lvl,3)What you need to do is alias this expression and the CREATE will pick up the alias as the column name, like this:
CREATE TABLE TEST_CARE AS
SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3) column3, len FROM test_care_lvl
WHERE LENGTH(old_care_lvl) =5
UNION ALL
SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
WHERE LENGTH(old_care_lvl) =7
UNION ALL
SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
WHERE LENGTH(old_care_lvl) =14
UNION ALL
SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3),LEN FROM test_care_lvl
WHERE LENGTH(old_care_lvl) =7 AND old_care_lvl ='Regular'
);You may not like the name "column3" so use something appropriate. -
Hello,
I may be barking up the wrong tree and asking this question in the wrong forum so please accept my apologies if this is the case.
I have access to a MYSql database through a ODBC connection and would like to create a report based on four tables (let's say A, B, C and D) where tables A & B hold biographical data and tables C & D contain different attribute detail with identical column names (attrib_name and attrib_desc) that relate to A & B .
The report I would like to create will list records from both A and B along with corresponding records from C and D merged into two columns attrib_name and attrib_desc.
I have tried a couple of versions of a union query but I just cannot seem to get it to generate the correct output.
Any help would be much appreciated.
Thank you
Paulhi Paul,
Command objects are written in syntax specific to the database that you're using, so you may be best off looking at mysql forums instead. plus you haven't really stated what the issue is that you experiencing.
given the above, here's a couple basic things about UNION syntax...
1 the number of fields selected must be the same
2 the corresponding fields should be in the same sequence
3 the types (e.g. date, integer) must match
4 in your SELECT statement use an AS 'name' for each field so that the field names match up in both sets in the query
you may also wish to use a UNION ALL instead of a UNION as UNION ALL will ensure that all records are brought back as opposed to UNION which does a check on a virtual record set to ensure that there's no duplicates...this in turn can cause performance to suffer a bit. -
Inventory on Hand Report - Using Union ALL - need two fields to be part of the group
Hi all,
I have created an Inventory "on Hand" Report that takes the Current Inventory from the Item Entry table and the Sales from Unposted Sales Line table and Transfers in and out from the Unposted Transfer Line table. I have joined the tables
using the UNION ALL function.
My problem is that the Transfer table has two locations whereas the other tables only have one. I am grouping on Location code from the Item Entry table which is equivalent to BOTH Transfer from location and the Transfer to.
As an example, there are 15lbs of inventory for Product A in Location #1 with a transfer out of 15 lbs. The Transfer out is going to Location #2
I don't know how to write the query or set up the group so that it recognizes both the Transfer to and the Transfer From fields
I want the report to look similar to the one below but I can only get it to show one of the locations. Is there some way to use the Union function and have one field in the first table be or equivalent to two fields in another?
Location Code
Item No.
Lbs
Sales Orders
Transfer Out
Transfer In
Available Inventory
Location #1
Product A
15
-15
Location #1
15
-15
Location #2
Product A
15
15
Location #2
15
15Hi Igor,
You can get a custom sort order added to your IP column without the need for a second column.
Consider that the sorting is done strictly left-to-right across a string in the column. The string can be any valid HTML content. So, you could wrap your string within, say, a SPAN tag and add an attribute to that tag that contains the sort order you need before the text that is displayed to the user. As long as the attribute is correctly structured (that is, all instances are of the same length, for example), then sorting will work correctly. For example:
SELECT
'<span title="' || PAD_IP_ADDRESS(IP) || '">' || IP || '</span>' Y
FROM ...Now you need to ensure that the PAD_IP_ADDRESS() function returns the correct values. In IP addresses, you have anything from "0.0.0.0" to "255.255.255.255". To get them to sort "numerically", you need to pad one or two digit numbers to get three digit numbers for each value - so, "0.0.0.0" becomes "000.000.000.000". You could create a function to do this - something like:
CREATE OR REPLACE FUNCTION PAD_IP_ADDRESS
pIP IN VARCHAR2
RETURN VARCHAR2
IS
vIP VARCHAR2(15);
vTEMP APEX_APPLICATION_GLOBAL.VC_ARR2;
vSEP VARCHAR2(1);
BEGIN
vSEP := '';
vIP := '';
vTEMP := APEX_UTIL.STRING_TO_TABLE(pIP,'.');
FOR x IN 1..vTEMP.COUNT
LOOP
vIP := vIP || vSEP || TRIM(TO_CHAR(TO_NUMBER(vTEMP(x)),'000'));
vSEP := '.';
END LOOP;
RETURN vIP;
END;The output from this would look something like:
<span title="001.001.001.001">1.1.1.1</span>
<span title="002.255.255.255">2.255.255.255</span>
<span title="010.001.199.098">10.1.199.098</span>Andy
Maybe you are looking for
-
Firefox redirects me to wrong sites 50% of the time. Only on Firefox
I get redirected when on the Firefox brwser 50% of the time == This happened == Every time Firefox opened == User Agent == Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4
-
Problem Creating Recordset in Dreamweaver CS5.5
Can you help? I am having with recordsets in Dreamweaver CS5.5, or rather the sudden (I don't know why this has suddenly happened) inability to create one. When I try to create a recordset query I get this error message and am prevented from creatin
-
How to find order no. from project no.
Hi, We are trying to create a custom report like CN47N. Now I want to find out order no. for any project no. entered. Can you suggest what tables to use to find order nos for any project?
-
Deleting Objectives from Appraisal Document
Hi All, I have a criteria group called behavioral competences placed in my document, now a free enhancement is assigned to allow the user to select a qualification from the qualification catalogue and place it in the document. However if a user adds
-
Checking whether a URL is active in 4.6C
Here's a different question for you. I've been asked to check whether a URL is active. Basically they want to check whether the webpage is still viewable and if it isn't, then send an e-mail. This will be a background job. Because 4.6C does not hav