Maximum number of joins in SELECT statement
Dear friends,
Can you tell me, how many max number of joins (inner & outer) we can make in ABAP.
For eg:
table 1: A B C fields
table 2: C D E fields
table 3: E F G fileds..............
Thanks in advance for your valuable time.
Best regards,
Satish
hi,
no limit for joins[inner or outer ] in a table , when we consider performance issue joins will reduce the performance of our program so go views instead of joins.
with cheers,
suresh babu aluri.
Similar Messages
-
Sort key too long - maximum number of columns in select statement
the sort key too long is caused by either too many group
functions or too many columns selected. Does anyone know the
maximum number of columns that can be selected in one statement ?The Oracle 9i reference states ...
The GROUP BY expression and all of the
nondistinct aggregates functions (for example,
SUM, AVG) must fit within a single database
block.
... and the Oracle 9i SQL Reference states that ...
An order_by_clause can contain no more than 255
expressions.
You could check your own documentation, but i think it will
be the same. -
Maximum number of joins in OpenSQL (java framework)
Hi,
I have a question on the restriction of the number of joins a OpenSQL can support??
I have searched in alot of places.. but the question remains unanswered....
Open SQL statements will work in any SAP R/3 System, regardless of the database system in use.... but does OpenSQl itself have any restrictions / maximum number of joins that it supports.
kindly need help on this ..
Regards,
Sana javeed
Edited by: Sana Javeed on Dec 6, 2011 5:02 AMi found a link which refers to the maximum number of tables after the FROM clause of the OpenSQL Query ....
where it mentions : To ensure program portability, specify no more than 15 tables in a query, including the tables in the from list and tables in subqueries. (Individual host database management systems may allow more than 15 tables.)
[http://docs.actian.com/ingres/9.2/opensql-reference-guide/3802-osql-from-clause|http://docs.actian.com/ingres/9.2/opensql-reference-guide/3802-osql-from-clause] -
How display number of row in select statement
How can I display number of row in select statement?
Table
data1 data2
xxx ccd
wss qwe
qws uij
I need get from SELECT statement:
1 xxx ccd
2 wss qwe
3 qws uijuser13734495 wrote:
Thank you from answer.
Statement
select rownum rn, data1, data2 from table
is good.
And what have I do went I use
select rownum rn, data1, data2 from table order by data1
and I get
3 qws uij
2 wss qwe
1 xxx ccd
I need
1 qws uij
2 wss qwe
3 xxx ccdhence the importance of describing the complete problem.
select
rownum,
data1,
data2
from(
select
data1,
data2
from
table
order by
data1) -
Inner join in select statement
hi,
i am using select statement like
SELECT ekkoebeln ekkobukrs ekkobstyp ekkobsart ekko~ernam
ekkolifnr ekkozterm ekkozbd1t ekkozbd2t ekko~zbd3t
ekkozbd1p ekkozbd2p ekkoekorg ekkoekgrp ekko~waers
ekkowkurs ekkokufix ekkobedat ekkokdate
Begin of Changes, RICEF : 293.
ekkozzhedg ekkozzheda ekkozzpba ekkozzpbubu lfa1~vbund
End of Changes, RICEF . 293.
lfa1land1 lfa1name1
ekpa~lifn2
INTO CORRESPONDING FIELDS OF TABLE iekko
FROM ekko
JOIN lfa1 ON lfa1lifnr = ekkolifnr
LEFT JOIN ekpa ON ekpaebeln = ekkoebeln AND
ekpa~ebelp = '00000' AND
ekpa~parvw = 'RS'
FOR ALL entries IN icooi
WHERE ekko~ebeln = icooi-refbn
AND ekko~zzhedg IN s_zzhedg
AND ekko~zzheda IN s_zzheda.
where in ekko table ,the fields zzhedg and zzheda are appended..but in the debugging mode i am unable to see this 2 field....in the output also....so how should i write my select query?Hi,
Is your select statement returning sy-subrc 0. In debugging mode may be your fields may not be visible in the screen since your internal table has many fields, you have to press >> forward button to check the fields.
Thanks & Regards,
Navneeth K. -
Default join in select statements
Hi guyz,
If I am using just Join in my select statement. What does it do by default
1. innter join
2. outer join
eg:
select vbeln posnr into table itab from vbak <b>join</b> vbap on vbakvbeln = vbapvbeln.
Thanks.Mgs,
By Default innerjoin.
See the diff.
Hi karan check also the "left outer join" statement.
It might help you if you need 1-N relation
// left outer Join
Table 1 Table 2
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
3
e2
f2
g2
h2
a3
b3
c3
2
4
e3
f3
g3
h3
a4
b4
c4
3
|--|||--|
Left Outer Join
|--||||||||--|
| A | B | C | D | D | E | F | G | H |
|--||||||||--|
| a1 | b1 | c1 | 1 | 1 | e1 | f1 | g1 | h1 |
| a2 | b2 | c2 | 1 | 1 | e1 | f1 | g1 | h1 |
| a3 | b3 | c3 | 2 |NULL|NULL|NULL|NULL|NULL|
| a4 | b4 | c4 | 3 | 3 | e2 | f2 | g2 | h2 |
|--||||||||--|
// Inner Join
Table 1 Table 2
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
3
e2
f2
g2
h2
a3
b3
c3
2
4
e3
f3
g3
h3
a4
b4
c4
3
Inner Join
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
1
e1
f1
g1
h1
a4
b4
c4
3
3
e2
f2
g2
h2
Pls. mark if useful -
Hi All,
I have 9 select Statements,i can combine these queries by 'UNION' to get the result....but the process will be tedious.
Is there any other option to do the same in a easy way.
Example :
SELECT ecv.creation_date "Initiation Date",
eceb.c_ext_attr1 "REPORTING PERSON",
eceb.c_ext_attr2 INITIATOR,
eceb.c_ext_attr3 "REPORTING PERSON TITLE",
eceb.d_ext_attr2 "AWARE DATE",
eceb.c_ext_attr4 TELEPHONE
FROM eng_changes_v ecv,
eng_changes_ext_b eceb
WHERE ecv.change_id = eceb.change_id
AND ecv.change_notice = 'COM-10034'
AND attr_group_id = 266;
UNION
SELECT eceb.c_ext_attr2 TYPE,
eceb.c_ext_attr3 INSTITUTION,
eceb.c_ext_attr4 TERRITORY,
eceb.c_ext_attr5 "CUSTOMER NAME",
eceb.c_ext_attr6 TITLE,
eceb.c_ext_attr7 ADDRESS,
eceb.c_ext_attr8 "ADDRESS 2",
eceb.c_ext_attr9 CITY,
eceb.c_ext_attr10 STATE,
eceb.n_ext_attr1 ZIP,
eceb.c_ext_attr11 COUNTRY,
eceb.c_ext_attr12 TELEPHONE,
eceb.c_ext_attr13 FAX
FROM eng_changes_v ecv,
eng_changes_ext_b eceb
WHERE ecv.change_id = eceb.change_id
AND ecv.change_notice = 'COM-10034'
AND attr_group_id = 267;
In this fashion i have 9 select statements.
Thanks in advance!
RamyaWell, this is not the silly EAV model …
but it does look as something that has been slightly abused on the dynamic/generic side.
You certainly do not want to UNION … it wouldn’t make sense anyway.
Think of your ATTR_GROUP_ID as identifiers of what could have been real tables
(dependents of ENG_CHANGES_V):
create view could_be_table_266 as
select change_id
,c_ext_attr1 REPORTING_PERSON
,c_ext_attr2 INITIATOR
,c_ext_attr3 REPORTING_PERSON_TITLE
,d_ext_attr2 AWARE_DATE
,c_ext_attr4 TELEPHONE
from eng_changes_ext_b
where attr_group_id = 266
create view could_be_table_267 as
select change_id
,c_ext_attr2 TYPE
,c_ext_attr3 INSTITUTION
,c_ext_attr4 TERRITORY
,c_ext_attr5 CUSTOMER NAME
,c_ext_attr6 TITLE
,c_ext_attr7 ADDRESS
,c_ext_attr8 ADDRESS_2
,c_ext_attr9 CITY
,c_ext_attr10 STATE
,n_ext_attr1 ZIP
,c_ext_attr11 COUNTRY
,c_ext_attr12 TELEPHONE
,c_ext_attr13 FAX
from eng_changes_ext_b
where attr_group_id = 267
Then join using your knowledge of what the “logical” relationship between these table would be … likely
select <columns_you_need_from x>
,<columns_you_need_from a>
,<columns_you_need_from b>
from eng_changes_v x
,could_be_table_266 a
,could_be_table_267 b
where x.change_id = a.change_id (+)
and x.change_id = b.change_id (+)
and x.change_notice = 'COM-10034'
Using column names like "REPORTING PERSON" rather than REPORTING_PERSON is just a pain in the …
What column headings one wants in a report/screen doesn’t have to drive the names of select list items in SQL.
TYPE is likely not a good name … reserved word -
Join a SELECT-Statement with a INDEX
can I force a SELECT-Statement to use a certain Table-INDEX?
f.e.
select * from table a
where a.key like '%p'
..forced index a.idx.--Yes. You can.
Use SQL hint.
select /*+ index (tablename indexname) */.
If the index is usable-Oracle will use it. If not -Oracle will see it as a remark. -
What is syntax for inner join of Select statement with Secondary Index
Hi Genies,
Here i have created the Secondary index for table COEP and also used for select query but there is no improvement in runtime . taking same time for select query without index as well as with index. my code is
SELECT * INTO CORRESPONDING FIELDS OF TABLE ITAB_COEP FROM COEP AS A
INNER JOIN COBK AS B ON ( A~BELNR = B~BELNR AND A~KOKRS = B~KOKRS AND A~GJAHR = B~GJAHR )
WHERE A~OBJNR = OBJNR
AND A~GJAHR = CURRY
AND B~GJAHR = CURRY
AND A~RBEST = ''
AND A~BEKNZ = 'S'
AND B~BELNR NE WA_COBK-BELNR
AND B~AWREF_REV = ''
AND B~AWORG_REV = ''
AND B~KOKRS = WA_COIOB-KOKRS
AND B~BLDAT BETWEEN START_DATE AND END_DATE
AND B~BLART IN ('SA','KA','KR','AB') %_HINTS ORACLE 'INDEX("COEP" "COEP~ZBU")'.
index name is ZBU.
please any one let me know is there any syntax mistakes? but while checking and during the runtime it does'nt shows any error.
Regards,
Thangam.PHi Genies,
Here i have created the Secondary index for table COEP and also used for select query but there is no improvement in runtime . taking same time for select query without index as well as with index. my code is
SELECT * INTO CORRESPONDING FIELDS OF TABLE ITAB_COEP FROM COEP AS A
INNER JOIN COBK AS B ON ( A~BELNR = B~BELNR AND A~KOKRS = B~KOKRS AND A~GJAHR = B~GJAHR )
WHERE A~OBJNR = OBJNR
AND A~GJAHR = CURRY
AND B~GJAHR = CURRY
AND A~RBEST = ''
AND A~BEKNZ = 'S'
AND B~BELNR NE WA_COBK-BELNR
AND B~AWREF_REV = ''
AND B~AWORG_REV = ''
AND B~KOKRS = WA_COIOB-KOKRS
AND B~BLDAT BETWEEN START_DATE AND END_DATE
AND B~BLART IN ('SA','KA','KR','AB') %_HINTS ORACLE 'INDEX("COEP" "COEP~ZBU")'.
index name is ZBU.
please any one let me know is there any syntax mistakes? but while checking and during the runtime it does'nt shows any error.
Regards,
Thangam.P -
Executing a stored procedure containing multiple Select statements
Post Author: Beverly
CA Forum: General
I am using Crystal 10.0 against a MS SQL 2000 server.
I am trying to create a report based on a stored procedure that contains multiple select statements. The sp requires a single parameter (Claim number) and contains 17 Select statements that produce results.
I am able to use the Add command and execute the sp with the parameter, but I am only getting the results of the first select statement in the sp back in my data set. Is there a way to have the data from each Select statement returned to my report?
I have used Crystal for a while, but pretty much for straight-forward reporting. I am familiar with the basics of SQL.
I would appreciate any help anyone can offer.
Thanks.Post Author: BISoftware
CA Forum: General
I believe Crystal Reports can only handle one recordset at a time, which means it can only handle a single select statement. The only way I can see around this would be to break up your stored procedure into multiple stored procedures, so that each only contains a single select statement. Then, use subreports to report on each individual sp. Hope this helps. - Davewww.BusinessSoftwareResource.com -
Maximum number of tables that can be outer joined with one table in a query
Hi All,
Iam new to sql, so can you please let me know What is the maximum number of tables that can be outer joined with one table in a query?
Thanks,
Srinisrinu2 wrote:
Iam new to sql, so can you please let me know What is the maximum number of tables that can be outer joined with one table in a query?
There is no limit to the number of tables you can outer join as long as you join them correctly.
SQL> with a as
2 (
3 select 1 id, 2 b_key, 3 c_key from dual union all
4 select 2 id, 1 b_key, 4 c_key from dual union all
5 select 3 id, 3 b_key, 1 c_key from dual union all
6 select 4 id, 4 b_key, 2 c_key from dual
7 ),
8 b as
9 (
10 select 1 id, 1 c_key2 from dual union all
11 select 2 id, 5 c_key2 from dual union all
12 select 3 id, 3 c_key2 from dual union all
13 select 4 id, 2 c_key2 from dual
14 ),
15 c as
16 (
17 select 1 key1, 1 key2, '1-1' dta from dual union all
18 select 1 key1, 2 key2, '1-2' dta from dual union all
19 select 1 key1, 3 key2, '1-3' dta from dual union all
20 select 1 key1, 4 key2, '1-4' dta from dual union all
21 select 2 key1, 1 key2, '2-1' dta from dual union all
22 select 2 key1, 2 key2, '2-2' dta from dual union all
23 select 2 key1, 3 key2, '2-3' dta from dual union all
24 select 2 key1, 4 key2, '2-4' dta from dual union all
25 select 3 key1, 1 key2, '3-1' dta from dual union all
26 select 3 key1, 2 key2, '3-2' dta from dual union all
27 select 3 key1, 3 key2, '3-3' dta from dual union all
28 select 3 key1, 4 key2, '3-4' dta from dual union all
29 select 4 key1, 1 key2, '4-1' dta from dual union all
30 select 4 key1, 2 key2, '4-2' dta from dual union all
31 select 4 key1, 3 key2, '4-3' dta from dual union all
32 select 4 key1, 4 key2, '4-4' dta from dual
33 )
34 select d.a_id, d.b_id, c.key1 as c_key1, c.key2 as c_key3, c.dta
35 from
36 c,
37 (
38 select
39 a.id as a_id, b.id as b_id, a.c_key, b.c_key2
40 from a, b
41 where a.b_key = b.id
42 ) d
43 where d.c_key = c.key1 (+)
44 and d.c_key2 = c.key2 (+);
A_ID B_ID C_KEY1 C_KEY3 DTA
3 3 1 3 1-3
4 4 2 2 2-2
2 1 4 1 4-1
1 2
SQL> -
Joins And For all Enteries in Select Statement
Could you please tell me when there is a high amount of data which is being handled in the table, does the use of INNER JOINS and FOR ALL ENTERIES in SELECT Statement decreases the system performance? ?
Can you also let me know where can i get some tips regarding do's and dont's for ABAP Programming, I want to increase my system performance.
Currently the programs which are being used are taking a lot of time for execution...
Its very URGENT!Hai Jyotsna
Go through the following Tips for improving Performence
For all entries
The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the length of the WHERE clause.
The plus
Large amount of data
Mixing processing and reading of data
Fast internal reprocessing of data
Fast
The Minus
Difficult to program/understand
Memory could be critical (use FREE or PACKAGE size)
Some steps that might make FOR ALL ENTRIES more efficient:
Removing duplicates from the driver table
Sorting the driver table
If possible, convert the data in the driver table to ranges so a BETWEEN statement is used instead of and OR statement:
FOR ALL ENTRIES IN i_tab
WHERE mykey >= i_tab-low and
mykey <= i_tab-high.
Nested selects
The plus:
Small amount of data
Mixing processing and reading of data
Easy to code - and understand
The minus:
Large amount of data
when mixed processing isnt needed
Performance killer no. 1
Select using JOINS
The plus
Very large amount of data
Similar to Nested selects - when the accesses are planned by the programmer
In some cases the fastest
Not so memory critical
The minus
Very difficult to program/understand
Mixing processing and reading of data not possible
Use the selection criteria
SELECT * FROM SBOOK.
CHECK: SBOOK-CARRID = 'LH' AND
SBOOK-CONNID = '0400'.
ENDSELECT.
SELECT * FROM SBOOK
WHERE CARRID = 'LH' AND
CONNID = '0400'.
ENDSELECT.
Use the aggregated functions
C4A = '000'.
SELECT * FROM T100
WHERE SPRSL = 'D' AND
ARBGB = '00'.
CHECK: T100-MSGNR > C4A.
C4A = T100-MSGNR.
ENDSELECT.
SELECT MAX( MSGNR ) FROM T100 INTO C4A
WHERE SPRSL = 'D' AND
ARBGB = '00'.
Select with view
SELECT * FROM DD01L
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
SELECT SINGLE * FROM DD01T
WHERE DOMNAME = DD01L-DOMNAME
AND AS4LOCAL = 'A'
AND AS4VERS = DD01L-AS4VERS
AND DDLANGUAGE = SY-LANGU.
ENDSELECT.
SELECT * FROM DD01V
WHERE DOMNAME LIKE 'CHAR%'
AND DDLANGUAGE = SY-LANGU.
ENDSELECT.
Select with index support
SELECT * FROM T100
WHERE ARBGB = '00'
AND MSGNR = '999'.
ENDSELECT.
SELECT * FROM T002.
SELECT * FROM T100
WHERE SPRSL = T002-SPRAS
AND ARBGB = '00'
AND MSGNR = '999'.
ENDSELECT.
ENDSELECT.
Select Into table
REFRESH X006.
SELECT * FROM T006 INTO X006.
APPEND X006.
ENDSELECT
SELECT * FROM T006 INTO TABLE X006.
Select with selection list
SELECT * FROM DD01L
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
ENDSELECT
SELECT DOMNAME FROM DD01L
INTO DD01L-DOMNAME
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
ENDSELECT
Key access to multiple lines
LOOP AT TAB.
CHECK TAB-K = KVAL.
ENDLOOP.
LOOP AT TAB WHERE K = KVAL.
ENDLOOP.
Copying internal tables
REFRESH TAB_DEST.
LOOP AT TAB_SRC INTO TAB_DEST.
APPEND TAB_DEST.
ENDLOOP.
TAB_DEST[] = TAB_SRC[].
Modifying a set of lines
LOOP AT TAB.
IF TAB-FLAG IS INITIAL.
TAB-FLAG = 'X'.
ENDIF.
MODIFY TAB.
ENDLOOP.
TAB-FLAG = 'X'.
MODIFY TAB TRANSPORTING FLAG
WHERE FLAG IS INITIAL.
Deleting a sequence of lines
DO 101 TIMES.
DELETE TAB_DEST INDEX 450.
ENDDO.
DELETE TAB_DEST FROM 450 TO 550.
Linear search vs. binary
READ TABLE TAB WITH KEY K = 'X'.
READ TABLE TAB WITH KEY K = 'X' BINARY SEARCH.
Comparison of internal tables
DESCRIBE TABLE: TAB1 LINES L1,
TAB2 LINES L2.
IF L1 <> L2.
TAB_DIFFERENT = 'X'.
ELSE.
TAB_DIFFERENT = SPACE.
LOOP
AT TAB1.
READ TABLE TAB2 INDEX SY-TABIX.
IF TAB1 <> TAB2.
TAB_DIFFERENT = 'X'. EXIT.
ENDIF.
ENDLOOP.
ENDIF.
IF TAB_DIFFERENT = SPACE.
ENDIF.
IF TAB1[] = TAB2[].
ENDIF.
Modify selected components
LOOP AT TAB.
TAB-DATE = SY-DATUM.
MODIFY TAB.
ENDLOOP.
WA-DATE = SY-DATUM.
LOOP AT TAB.
MODIFY TAB FROM WA TRANSPORTING DATE.
ENDLOOP.
Appending two internal tables
LOOP AT TAB_SRC.
APPEND TAB_SRC TO TAB_DEST.
ENDLOOP
APPEND LINES OF TAB_SRC TO TAB_DEST.
Deleting a set of lines
LOOP AT TAB_DEST WHERE K = KVAL.
DELETE TAB_DEST.
ENDLOOP
DELETE TAB_DEST WHERE K = KVAL.
Tools available in SAP to pin-point a performance problem
· The runtime analysis (SE30)
· SQL Trace (ST05)
· Tips and Tricks tool
· The performance database
Optimizing the load of the database
Using table buffering
Using buffered tables improves the performance considerably. Note that in some cases a statement can not be used with a buffered table, so when using these statements the buffer will be bypassed. These statements are:
Select DISTINCT
ORDER BY / GROUP BY / HAVING clause
Any WHERE clause that contains a sub query or IS NULL expression
JOIN s
A SELECT... FOR UPDATE
If you wan t to explicitly bypass the buffer, use the BYPASS BUFFER addition to the SELECT clause.
Use the ABAP SORT Clause Instead of ORDER BY
The ORDER BY clause is executed on the database server while the ABAP SORT statement is executed on the application server. The database server will usually be the bottleneck, so sometimes it is better to move the sort from the database server to the application server.
If you are not sorting by the primary key ( E.g. using the ORDER BY PRIMARY key statement) but are sorting by another key, it could be better to use the ABAP SORT statement to sort the data in an internal table. Note however that for very large result sets it might not be a feasible solution and you would want to let the database server sort it.
Avoid the SELECT DISTINCT Statement
As with the ORDER BY clause it could be better to avoid using SELECT DISTINCT, if some of the fields are not part of an index. Instead use ABAP SORT + DELETE ADJACENT DUPLICATES on an internal table, to delete duplicate rows.
Thanks & regards
Sreenivasulu P -
Maximum number of AP supported has already joined cisco
Dear all,
We have vWLC, AP connected through MPLS network, we also have ap base license for 15 AP, the problem is that AP cant joint to WLC because of
this error:
Maximum number of AP supported has already joined cisco
WLC shows that all 15 licenses are used, but we have only 3 AP
What is that? bug or not?, everything worked fine before we put new 4 AP into the network
thank you
I attached outputs in photos:This license is evaluate and it works fine, but when it is our license it shows no AP in summary
(Cisco Controller) >show sysinfo
Manufacturer's Name.............................. Cisco Systems Inc.
Product Name..................................... Cisco Controller
Product Version.................................. 7.4.100.60
RTOS Version..................................... 7.4.100.60
Bootloader Version............................... 7.4.100.60
Emergency Image Version.......................... 7.4.100.60
Build Type....................................... DATA + WPS
System Name...................................... Cisco VWLC
System Location.................................. ESXI
System Contact...................................
System ObjectID.................................. 1.3.6.1.4.1.9.1.1631
IP Address....................................... 192.168.6.1
System Up Time................................... 0 days 17 hrs 29 mins 9 secs
System Timezone Location......................... (GMT +4:00) Muscat, Abu Dhabi
System Stats Realtime Interval................... 5
System Stats Normal Interval..................... 180
Configured Country............................... Multiple Countries:BY,MX,US
--More-- or (q)uit
State of 802.11b Network......................... Enabled
State of 802.11a Network......................... Enabled
Number of WLANs.................................. 7
Number of Active Clients......................... 41
Memory Current Usage............................. Unknown
Memory Average Usage............................. Unknown
CPU Current Usage................................ Unknown
CPU Average Usage................................ Unknown
Burned-in MAC Address............................ 00:50:56:9F:68:43
Maximum number of APs supported.................. 200
(Cisco Controller) >show ap summary
Number of APs.................................... 3
Global AP User Name.............................. Not Configured
Global AP Dot1x User Name........................ Not Configured
AP Name Slots AP Model Ethernet MAC Location Port Country Priority
Meeting_Room 2 AIR-LAP1142N-E-K9 54:75:d0:f5:3a:e4 default location 1 BY 1
Fttb 2 AIR-CAP3602I-A-K9 30:f7:0d:29:03:42 default location 1 MX 1
Technical 2 AIR-LAP1142N-E-K9 c8:9c:1d:f4:72:8a default location 1 BY 1 -
How to JOIN the results of multiple SELECT statements
Hello,
I currently have a table where each row represents a single census date for a given tag number, where each tag number can have multiple census dates and data which are represented by their own row in the table.
I currently have 2 SELECT statements that select all tag numbers given a census date, and would like to combine those 2 queries so that the data is presented in a manner such that for each tag number, instead of obtaining 2 rows for each tag number, I would be presented with 1 row for each tag number consisting of three columns: tag_number, data1, and data2.
Both of the requested dates are not necessarily present for all tag numbers, and in the event that only one date is present, the other column should contain null, but if both dates are not present for a given tag number, the tag number is omitted.
The two queries I would like to JOIN are:
SELECT a.tag_number, a.data AS data1
FROM tab1 a
WHERE
a.census_date='11/21/2009'and
SELECT b.tag_number, b.data AS data2
FROM tab2 b
WHERE
b.census_date='11/24/2009'The table from which I am selecting the data looks like such:
tag_number census_date data
1 11/21/2009 10
1 11/23/2009 11
1 11/24/2009 12
2 11/19/2009 13
2 11/21/2009 14And the data that I would like to result looks like:
tag_number data1 data2
1 10 12
2 14 nullAny help would be greatly appreciated.
Thank you in advance,
-Justin
Edited by: m8r-qbkka9 on Nov 24, 2009 4:17 PMHi,
This looks like a job for pivot
SELECT a.tag_number
, MAX (CASE WHEN a.census_date = TO_DATE ('11/21/2009'
'MM/DD/YYYY'
THEN a.data
END
) AS data1
, MAX (CASE WHEN a.census_date = TO_DATE ('11/24/2009'
'MM/DD/YYYY'
THEN a.data
END
) AS data2
FROM tab1 a
WHERE a.census_date IN ( TO_DATE ( '11/21/2009'
, 'MM/DD/YYYY'
, TO_DATE ( '11/21/2009'
, 'MM/DD/YYYY'
GROUP BY a.tag_number
;Comparing DATEs to stirngs, like '11/24/2009', is simply asking for trouble.
Always use a conversion function (like TO_DATE) or DATE literals instead. -
Select statement Table Join sequence (Performance)
Hi,
I have 3 tables Header (Hdr), Item (Itm) and Schedule Line (Sdl) table. The number of entries is max in Sdl table (Eg: Hdr = 1000; Item = 20000 and Sdl = 200000 records). I need to join these 3 tables in my SELECT statement to fetch the required records.
Case A:
Header AS HDR
JOIN Item AS ITM
ON HDRORDID = ITMORDID
AND HDRVRSIOID = ITMVRSIOID
JOIN ScheduleLine AS SDL
ON ITMITMID = SDLITMID
Case B:
ScheduleLine AS SDL
JOIN Item AS ITM
ON ITMITMID = SDLITMID
JOIN Header AS HDR
ON HDRORDID = ITMORDID
AND HDRVRSIOID = ITMVRSIOID
Questions:
1) The performance of the Select query is really bad with Case A and very good (really fast) with Case B. Will the number of records in the tables used determine the sequence of join in the Select statement ?
2) If yes, is this independent of database used ? That is, will the behaviour be the same in all databases (Eg: Oracle, DB2, SQL Server, etc) ?
Appreciate your help.
Thanks,
KarthikI believe that the performance discrepancy between the two versions is caused by you not specifying the joins correctly (i.e. not qualifying the header and item at schedule level as I mentioned previously).
CAse A.
Header AS HDR
JOIN Item AS ITM
ON HDRORDID = ITMORDID
AND HDRVRSIOID = ITMVRSIOID
JOIN ScheduleLine AS SDL
ON ITMITMID = SDLITMID
reads all 1000 hDRs, joins all 20000 items correctly to these BUT then joins schedule lines only by item id so there will be a very large number of matches. i.e. any item with itemid 10 will match to EVERY SDL with itemid 10. as there are 20000 items and 200000 schedule lines this will be massive!
Case B:
ScheduleLine AS SDL
JOIN Item AS ITM
ON ITMITMID = SDLITMID
JOIN Header AS HDR
ON HDRORDID = ITMORDID
AND HDRVRSIOID = ITMVRSIOID
This will not have the same amount of DB traffic as the SDL is now the driving force. It will still match more than you intend but will only be reading the items redundantly trather than the more voluminous schedules.
Basically, your sql is wrong and should qualify the matches right down to schedule line level as per my earlier post. When you have changed the sql, try the two alternatives again and see if there is any performance differences. I suspect that there will not be, but it will be interesting to find out for sure.
Maybe you are looking for
-
How do i use a Bluetooth phone to connect my Mac to the internet?
Please help me connect to the internet using my Bluetooth enabled phone's GPRS feature. I know an easier way would be to use Launch2net...but at 75Euros...too expensive. It used to be easy prior to Leopard but since I've upgraded to Leopard...the fea
-
I share my apple id but dont want to share contacts so what do i need to do?
i share my apple id but dont want to share contacts so what do i need to do?
-
Some MacBook hardly finding specs
Hi there, I've a late 2010 MacBook, someone knows if I can get sound output through mini display port, and if it's possible to stream audio and video through AirPlay to an Apple TV. Thanks a lot!! -Gianluca
-
Issues with simulations inserted into Powerpoint projects
When I import PowerPoint slides into a Captivate project, all is fine. However when I try to insert screens from a simulation recording, the simulation screens that appear only display about 80% of the recorded screen capture. I am trying to determ
-
I can't navigate between tabs using a mouse click since I installed latest version of Firefox
Running ver 30. which is fine, but I cannot switch between open tabs using a left mouse click on the tab I wish to activate, as I have been doing for years. Have to use Ctrl-Tab instead. Don't like this. This problem started with this version of FF.