Inner join is not removing duplicates!!
Table name is customers
CNUM CNAME CITY RATING SNUM
1 2001 Hoffman London 100 1001
2 2002 Giovanni Rome 200 1003
3 2003 Liu San Jose 200 1002
4 2004 Grass Berlin 300 1002
5 2006 Clemens London 100 1001
6 2008 Cisneros San Jose 300 1007
7 2007 Perira Rome 100 1004
Query is
To Find all pairs of customers haveing the same rating
I have tried:
SELECT c.cname,cb.cname FROM customers c INNER JOIN customers cb ON c.rating=cb.rating AND c.cname!=cb.cname
CNAME CNAME
1 Perira Hoffman
2 Clemens Hoffman
3 Liu Giovanni
4 Giovanni Liu
5 Cisneros Grass
6 Perira Clemens
7 Hoffman Clemens
8 Grass Cisneros
9 Clemens Perira
10 Hoffman Perira
Ideally it should till 5 rows but it should not return such rows for an e.g. Hoffman Perira since I got Perira Hoffman already. Your repsonse will be appreciated.
Thanks,
Vaibhav
Hi, Vaibhav,
914683 wrote:
Table name is customers
CNUM CNAME CITY RATING SNUM
1 2001 Hoffman London 100 1001
2 2002 Giovanni Rome 200 1003
3 2003 Liu San Jose 200 1002
4 2004 Grass Berlin 300 1002
5 2006 Clemens London 100 1001
6 2008 Cisneros San Jose 300 1007
7 2007 Perira Rome 100 1004
Query is
To Find all pairs of customers haveing the same rating
I have tried:
SELECT c.cname,cb.cname FROM customers c INNER JOIN customers cb ON c.rating=cb.rating AND c.cname!=cb.cnameMaybe what you want is
SELECT c.cname
, cb.cname
FROM customers c
INNER JOIN customers cb ON c.rating = cb.rating
AND c.cname < cb.cname -- not !=
CNAME CNAME
1 Perira Hoffman
2 Clemens Hoffman
3 Liu Giovanni
4 Giovanni Liu
5 Cisneros Grass
6 Perira Clemens
7 Hoffman Clemens
8 Grass Cisneros
9 Clemens Perira
10 Hoffman PeriraThe title you chose for this thread is "inner join is not removing duplicates!!".
Inner joins (or any other kinds of joins) are not supposed to remove duplicates. Use SELECT DISTINCT to remove duplicates, that is, completely identical rows.
You don't have any duplicates. For example, these rows from your result set:
` CNAME CNAME
1 Perira Hoffman
10 Hoffman Periraare not identical; in fact, both columns are different.
Ideally it should till 5 rows but it should not return such rows for an e.g. Hoffman Perira since I got Perira Hoffman already. Please post the exact output you want from that sample data. (As Hoek said, you should post CREATE TABLE and INSERT statements for the sample data, too.)
Similar Messages
-
Link for BUT000 table and ADRC in CRM and inner join is not working in PCUI
Hi Gurus,
Please tell me the link btween BUT000 and ADRC table. and i wrote one inner join between BUT000 and BUT0id table but it not working. I m in CRM 4.0 version working with PCUI.
select but000partner but000name_org1 but000name_org2 but000bus_sort1 but0id~parnter1
but0ididnumber from but000 inner join but0id on but0idpartner = but000~parnter
into corresponding fields of table it_result where partner in s_partner.
It is giving error as partner unknown from but000 table. I delcared everything and tried with alias names also.
please clarify me.
regards,
Ramakrishna.Hi Frederic,
thanks a lot. But is inner join between BUT000 and BUT0ID will work. for me it is not working. plesae see this code.
tables : but000,
but0id,
crmm_but_custno,
adrc.
types : begin of typ_but000,
partner type bu_partner,
name_org1 type BU_NAMEOR1,
name_org2 type BU_NAMEOR2,
bu_sort1 type BU_SORT1,
idnumber type BU_ID_NUMBER,
partner1 type bu_partner,
end of typ_but000.
data: lt_but000 type table of typ_but000,
ls_but000 like line of lt_but000.
*select-options : s_partnr for but000-partner.
start-of-selection.
select but000partner but000name_org1 but000name_org2 but000bu_sort1 but0id~parnter1
but0id~idnumber into corresponding fields of table lt_but000 from but000
inner join but0id on but0idpartner = but000parnter. " where partner in s_partner.
it is giving error as but000-partner is not know or but0id-partner not known.
So, i think if it not works then i should write two select stmts.
please clarify me.
i gave u rating.
thanks
ramakrishna. -
Inner join query not working properly
Hi everyone,
It does not gives any error, but it is not fetching any values...but when i dont include fourth table CSKT AND THE FIELD LTEXT it is fetching the values.
SELECT SINGLE
T1~PERNR
T1~BEGDA
T1~ENAME
T1~PLANS
T1~KOSTL
T2~STRAS
T2~PSTLZ
T2~ORT01
T3~PLSTX
T4~LTEXT
INTO FS_TAB
FROM PA0001 AS T1
INNER JOIN PA0006 AS T2 ON T1PERNR eq T2PERNR
INNER JOIN T528T AS T3 ON T1PLANS EQ T3PLANS
INNER JOIN CSKT AS T4 ON T1KOSTL EQ T4KOSTL
WHERE T1~PERNR eq p_pernr.Change like this
SELECT SINGLE
T1~PERNR
T1~BEGDA
T1~ENAME
T1~PLANS
T1~KOSTL
T2~STRAS
T2~PSTLZ
T2~ORT01
T3~PLSTX
T4~LTEXT
INTO FS_TAB
FROM PA0001 AS T1
INNER JOIN PA0006 AS T2 ON T1~PERNR eq T2~PERNR
INNER JOIN T528T AS T3 ON T1~PLANS EQ T3~PLANS
LEFT OUTER JOIN CSKT AS T4 ON T1~KOSTL EQ T4~KOSTL
WHERE T1~PERNR eq p_pernr.
OR
SELECT SINGLE
T1~PERNR
T1~BEGDA
T1~ENAME
T1~PLANS
T1~KOSTL
T2~STRAS
T2~PSTLZ
T2~ORT01
T3~PLSTX
T4~LTEXT
INTO FS_TAB
FROM PA0001 AS T1
LEFT OUTER JOIN PA0006 AS T2 ON T1~PERNR eq T2~PERNR
LEFT OUTER JOIN T528T AS T3 ON T1~PLANS EQ T3~PLANS
LEFT OUTER JOIN CSKT AS T4 ON T1~KOSTL EQ T4~KOSTL
WHERE T1~PERNR eq p_pernr.
as long as the table is not used in where condition, u can use left outter join. -
Edit form with an Inner Join - Can not update/delete data?!
Hi all,
I have an Edit form which shows me data from 2 tables (through an Inner Join SQL-Statement). I just realized that I can not edit data anymore, the following error msg appears:
Error in mru internal routine: ORA-20001: no data found in tabular form
Error Unable to process update.
OK
Can someone please help me?The ringed in red are from the second table, but the first table has some more data. Here is the SQL Statement I have (D1 and D2 are from the second table - Whereas the DOBJ_NR1 and the DOBJ_NR2 are both primary keys and foreign keys in table one, but the user selects the key from table two...):
SELECT
D1.DOBJ_NR DOBJ_NR1,
D1.NAMSP NAMSP1,
D1.DOBJ_NAME DOBJ_NAME1,
D2.DOBJ_NR DOBJ_NR2,
D2.NAMSP NAMSP2,
D2.DOBJ_NAME DOBJ_NAME2,
R.RS_NAME,
R.ROLE1TO2,
R.CARDMIN1TO2,
R.CARDMAX1TO2,
R.ROLE2TO1,
R.CARDMIN2TO1,
R.CARDMAX2TO1,
R.ON_DELETE,
R.ON_UPDATE,
R.O_RS_COMMENT,
R.INS_BY REL_INS_BY
FROM
DO_RELATIONSHIP R
INNER JOIN DATAOBJECT D1 ON R.DOBJ1_NR = D1.DOBJ_NR
INNER JOIN DATAOBJECT D2 ON R.DOBJ2_NR = D2.DOBJ_NR
Edited by: user12067949 on Dec 5, 2009 3:18 AM -
DataProvider.merge() method seems to not remove duplicate items
Using the DataProvider class to instantiate UI Components
data, I need to merge dataProvider data and remove any duplicate
items that may result from the merging process. It is supposed
(according to the manual) that the merge method behaves just as i
desire, but actually the data is being merged with duplicates. Any
hints?The docs are a little ambiguous. There is no actual "removal"
of items. The
method iterates the new data items and appends those that are
not already in
the provider. Since each item is an Object instance, they
must be the same
object to be equal.
In this example, the commonItem is "removed" during the
merge, but there are
still two instances in the original list
var commonItem:Object = {label:"itemX"};
var data1:Array = [
{label:"item1"},
commonItem,
commonItem,
{label:"item2"}
var data2:Array = [
{label:"item1"},
commonItem , // duplicated item
{label:"item3"}
var dp:DataProvider = new DataProvider(data1);
dp.merge(data2);
var myList:List = new List();
myList.dataProvider = dp; -
How to return all rows with duplicate values? Inner join not working!
I have a 3 column table:
location (pk), name, size
I am attempting to select pairs of entries that have the same
name and size but different values for location (it is the
primary key.) My inner join does not seem to return what I need:
select a.location, a.name, a.size, b.location, b.name, b.size
from mytable a, mytable b where a.name = b.name and a.size =
b.size and a.location <> b.location;One solution is like this:
SELECT dname, loc, deptno
FROM dept
WHERE (dname, loc) IN
(SELECT dname, loc
FROM dept
GROUP BY dname, loc
HAVING COUNT (*) > 1
ORDER BY dname, loc, deptno
Regards
Zlatko Sirotic -
Inner join command is not supporting pooled table
Hi Forum,
I'm new to abap. I tried passing fields of two tables into a single table using inner join command. But one of the tables is a pooled table so the command "inner join" is not supporting that. How to pass the fields in those two tables into a single table? Kindly help me out.
Rgrds,
MahathiHi ....
U can't perform JOIN with Pooled or Cluster tables
trying to join A018 and KONP .... here A018 is Pooled table... Look at below threads...
Re: abap query join A018/KONP
Can't perform join table
Hope it will solve your problem..
<b>Reward points if useful.</b>
Thanks & Regards
ilesh 24x7 -
Hi,
In my report List of Block Customer's, INNER JOIN is not working..
Code:----
SELECT DISTINCT M1KUNNR M1KTOKD M1NAME1 M1CASSD M1AUFSD M1LIFSD M1~FAKSD INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM KNA1 AS M1 INNER JOIN KNVV AS M2 ON M1KUNNR = M2KUNNR
WHERE M1~KTOKD IN ('0001' , 'KTOKD')
AND M1~CASSD EQ 'X'
OR M1~AUFSD NE ''
OR M1~LIFSD NE ''
OR M1~FAKSD NE ''
OR (M2~AUFSD NE ''
OR M2~LIFSD NE ''
OR M2~FAKSD NE ''
OR M2~CASSD EQ 'X'.
Here, condition on 0001 is not matching..
Plz tell me, what is the problem in it..
Thanks
Edited by: Prince Kumar on Oct 20, 2008 9:37 AMhi,
please use " FOR ALL ENTRIES " as it is better performance wise also rather then inner joins
and for syntax refer this code:
Exporting all flight data for a specified departure city. The relevant airlines and flight numbers are first put in an internal table entry_tab, which is evaluated in the WHERE condition of the subsquent SELECT statement.
PARAMETERS p_city TYPE spfli-cityfrom.
TYPES: BEGIN OF entry_tab_type,
carrid TYPE spfli-carrid,
connid TYPE spfli-connid,
END OF entry_tab_type.
DATA: entry_tab TYPE TABLE OF entry_tab_type,
sflight_tab TYPE SORTED TABLE OF sflight
WITH UNIQUE KEY carrid connid fldate.
SELECT carrid connid
FROM spfli
INTO CORRESPONDING FIELDS OF TABLE entry_tab
WHERE cityfrom = p_city.
SELECT carrid connid fldate
FROM sflight
INTO CORRESPONDING FIELDS OF TABLE sflight_tab
FOR ALL ENTRIES IN entry_tab
WHERE carrid = entry_tab-carrid AND
connid = entry_tab-connid.
thanks and regards
RAHUL -
Data is not fetching in inner join
Hi Experts,
I developed a select query using inner joins, all the fields data is gettting appended, but one field DISPO data is not getting appeneded. please check the innerjoin and suggest me ur soluitons.
MODULE GET_DATA OUTPUT.
select arbpl
sptag
aufnr
plnum
posnr
plnfl
werks from s022
into table it_s022
where arbpl in s_arbpl
and werks in s_werks
and sptag in s_sptag
and matnr in s_matnr.
if sy-subrc eq 0.
select a~aufnr
a~posnr
a~kdauf
a~pgmng
a~plnum
a~strmp
b~plnty
b~gamng
b~igmng
b~iasmg
b~rmnga
b~gstrp
b~rsnum
b~plnbez
b~dispo
c~maktx
b~plnnr
b~plnty
b~zaehl
d~vornr
d~ltxa1
b~aufpl
b~aplzt
e~astnr
into corresponding fields of table it_afpo from afko as b
inner join afpo as a
on a~aufnr = b~aufnr
inner join makt as c
on b~plnbez = c~matnr
inner join plpo as d
on b~plnnr = d~plnnr
and b~plnty = d~plnty
and b~zaehl = d~zaehl
inner join aufk as e
on b~aufnr = e~aufnr
inner join marc as f
on bplnty = fmatnr
for all entries in it_s022
where b~aufnr = it_s022-aufnr.
and e~erdat = it_s022-sptag
and a~posnr = it_s022-posnr
and a~plnum = it_s022-plnum . .
if sy-subrc eq 0.
it_afpo1[] = it_afpo[].
sort it_afpo1 by aufpl." aplzt."""
delete ADJACENT DUPLICATES FROM it_afpo1 COMPARING aufpl." aplzt ."""
select aufpl
aplzl
fsavd
fsavz
ssedd
ssedz
mgvrg
FROM afvv INTO TABLE It_afvv
FOR ALL ENTRIES IN IT_afpo1
WHERE aufpl = IT_afpo1-aufpl.
and aplzl = it_afpo1-aplzt.
endif.
loop at it_afpo into wa_afpo.
DATA : G_SLNO(8) TYPE C.
G_SLNO = G_SLNO + 1.
wa_afpo-slno = g_slno.
move-corresponding wa_afpo to wa_final.
move-corresponding wa_afko to wa_final.
read table it_afvv into wa_afvv with key
aufpl = wa_afpo-aufpl binary search."aplzl = wa_afpo-aplzt binary search."""
*read table it_afko into wa_afko with key aufnr = wa_final-aufnr.
IF SY-SUBRC EQ 0.
move-corresponding wa_afvv to wa_final.
bal_qty = wa_final-gamng - wa_final-igmng.
move : wa_afpo-slno to wa_final-slno,
wa_afpo-aufnr to wa_final-aufnr,
wa_afpo-posnr to wa_final-posnr,
wa_afpo-kdauf to wa_final-kdauf, " Sales order Number
wa_afpo-pgmng to wa_final-pgmng, " Order item qty
wa_afpo-plnum to wa_final-plnum, " Planned Order Qty
wa_afpo-strmp to wa_final-strmp, " Planned Order Date
wa_afpo-gstrp to wa_final-gstrp, " Basic Finish date
wa_afpo-rsnum to wa_final-rsnum, " Number of Reservation
wa_afpo-plnbez to wa_final-plnbez, " Material Number
wa_afpo-maktx to wa_final-maktx,
wa_afpo-plnnr to wa_final-plnnr,
wa_afpo-plnty to wa_final-plnty,
wa_afpo-zaehl to wa_final-zaehl,
wa_afpo-vornr to wa_final-vornr,
wa_afpo-ltxa1 to wa_final-ltxa1,
wa_afpo-aufpl to wa_final-aufpl,
wa_afvv-fsavd to wa_final-fsavd,
wa_afvv-fsavz to wa_final-fsavz,
wa_afvv-ssedd to wa_final-ssedd,
wa_afvv-ssedz to wa_final-ssedz,
wa_afvv-mgvrg to wa_final-mgvrg,
wa_afko-igmng to wa_final-igmng,
wa_afko-iasmg to wa_final-iasmg,
wa_afko-rmnga to wa_final-rmnga,
wa_afko-dispo to wa_final-dispo,
wa_afko-bal_qty to wa_final-bal_qty,
wa_aufk-astnr to wa_final-astnr,
wa_afpo-text to wa_final-text.
*bal_qty = wa_final-gamng - wa_final-igmng.
*bal_qty = wa_afko-bal_qty.
endif.
append wa_final to it_final.
clear:wa_final ,wa_afpo,wa_afvv,wa_aufk,wa_afko.
endloop.
endif.
ENDMODULE. " GET_DATA OUTPUT
*& Module DISPLAY_DATA OUTPUT
text
MODULE DISPLAY_DATA OUTPUT.
IF REF_CONTAINER IS INITIAL.
PERFORM FIELD_CAT.
CREATE OBJECT REF_CONTAINER
EXPORTING
PARENT =
CONTAINER_NAME = 'CUSTOM_CONTROL'
STYLE =
LIFETIME = lifetime_default
REPID =
DYNNR =
NO_AUTODEF_PROGID_DYNNR =
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
CREATE_ERROR = 3
LIFETIME_ERROR = 4
LIFETIME_DYNPRO_DYNPRO_LINK = 5
others = 6
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
L_LAYO-ZEBRA = 'X'.
L_LAYO-GRID_TITLE = 'JOB CARD'.
data: variant type disvariant.
CREATE OBJECT REF_ALV_GRID
EXPORTING
I_SHELLSTYLE = 0
I_LIFETIME =
I_PARENT = REF_CONTAINER
I_APPL_EVENTS = space
I_PARENTDBG =
I_APPLOGPARENT =
I_GRAPHICSPARENT =
I_NAME =
I_FCAT_COMPLETE = SPACE
EXCEPTIONS
ERROR_CNTL_CREATE = 1
ERROR_CNTL_INIT = 2
ERROR_CNTL_LINK = 3
ERROR_DP_CREATE = 4
others = 5
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
l_variant-report = sy-cprog.
*data: l_prnt type lvc_s_prnt.
*l_prnt-print = 'X'.
SORT T_FCAT.
call method ref_alv_grid->set_ready_for_input
exporting
i_ready_for_input = 1.
create object event_receiver.
set handler event_receiver->handle_top_of_page for ref_alv_grid.
CALL METHOD REF_ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME =
is_variant = variant "l_variant
i_save = 'X'
I_DEFAULT = 'X'
IS_LAYOUT = L_LAYO
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
IR_SALV_ADAPTER =
CHANGING
IT_OUTTAB = IT_final[]
IT_FIELDCATALOG = T_FCAT
IT_SORT =
IT_FILTER =
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
others = 4
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
create object g_event_receiver.
set handler g_event_receiver->handle_user_command for ref_alv_grid.
set handler g_event_receiver->handle_toolbar for ref_alv_grid.
§ 4.Call method 'set_toolbar_interactive' to raise event TOOLBAR.
call method ref_alv_grid->set_toolbar_interactive.
call method cl_gui_control=>set_focus exporting control = ref_alv_grid.
ENDIF.
ENDMODULE. " DISPLAY_DATA OUTPUT
*& Module STATUS_0100 OUTPUT
text
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'MAIN001'.
SET TITLEBAR 'xxx'.
Regards,
Bharath KumarI agree with Shiva Kumar - most likely there is no such field in it_afpo. A few more suggestions though:
1) Do not post large pieces of code here - if you have a question about a particular SELECT statement, post only that statement and relevant data definitions. No one is going to read your whole program anyway - we have work to do too.
2) Your JOIN is way too big and would be difficult to analyze if anything goes wrong. You might want to start with smaller SELECTs and, when you're sure everything is working correctly, then combine them into one. Also huge JOINT is not necessarily more efficient.
3) You don't have to use aliases "AS a... AS b", etc. Instead, just use the table name, e.g. AFKO... AFPO... .It is much easier to read this way. The aliases are needed only if you're joining the same table more than once. Also they're not limited to one letter either. -
Inner Join of 3 tables is correct or not?
Hi Guys ,
I have a requirement where i have to join 3 tables i dont know whether the inner Join which i wrote for 3 tables is correct or not.I am not getting any Syntax error but whether the logci below which i wrote gets all the records or not.
The Requirement is
"c. Select the BOL Number entered in the screen and query the table LIKP with the BOL number in the field LIKP-BOLNR. Gather the list of ALL delivery documents (LIKP-VBELN) that is outputted.
d. Query the list of the delivery documents obtained into the table VBFA in the field VBFA- VBELV. From the output that is displayed, select the Follow-On Document Field (VBFA-VBELN) for that item whose Subsequent Document Category (VBFA- VBTYP_N) is R and the Movement Type (VBFA- BWART) is 641. Get the Follow-On document number for each of the above Delivery Document number.
e. Query the table EKBE with the Follow On document obtained above in the field Material Document (EKBE- BELNR). Perform this activity for each of the follow on document obtained above. Get the resultant Purchase Order (EKBE-EBELN) and Item Number (EKBE-EBELP) from the query. After querying will all the Follow-On Documents, get the unique list of PO number and Item Number.
The logic which i wrote is
Begin of t_PoolSTO_out,
BOLNR type LIKP-BOLNR,
EBELN type EKBE-EBELN,
EBELP type EKBE-EBELP,
VBELN type LIKP-VBELN,
VBELNV type VBFA-VBELN,
End of t_PoolSTO_out.
Data: i_PoolSTO type Standard table of t_PoolSTO_out.
Select
a~BOLNR
c~EBELN
c~EBELP
a~VBELN
b~VBELN
from LIKP as a
Inner Join VBFA as b on aVBELN = bVBELV
Inner Join EKBE as c on bVBELN = cBELNR
into Table i_PoolSTO
Where a~BOLNR in S_LBLNE and
b~VBTYP_N = 'R' and
b~BWART = '641'.
My doubt is whether the logic works or not i Mean does i getall the rrecords based on the requirement.?
If not please tell any alternative logic?
Thanks,
Gopi Anne.Hi Gopi,
Your code is Good.
But try to avoid Inner join with more number of Tables ...because this is a performance issue..
try to use..
select (primary key fields mainly,other fields) from LIKP into itab where bolnr in p_bolnr(paramater).
next try to use for all entries option..
select (primary key fields mainly,other fields) from VBFA for all entries in itab where (give the condition)....
simillarly do for the other select ....ok this will try to reduce the performance issue....
<b><REMOVED BY MODERATOR></b>
Message was edited by:
Alvaro Tejada Galindo -
Inner Join resulting in many, many duplicates
I ran an Inner Join but it returned many, many duplicates. Any idea why that would occur?
One Answer from a different thread:
Because you may be having improper Join condition what has a One to many or a Many to many relationship between the tables. We do not have the data, and hence cannot comment over it. However, since the original issue is resolved, I suggest you close this thread and ask the question in another thread.
What do I look for to identify an improper join?Please don't start another discussion for the same issue.
Continue on your existing thread where the answers and advice you've already been given can be seen, so that people don't end up giving the same advice you've already had.
Answers on other thread: Inner Join error
Locking this thread -
Drag-n-n-drop query joins uses WHERE, not INNER JOIN syntax
When I highlight a few tables and drag them onto the sql worksheet, it will build a select statement for me and join the tables by their foreign keys.
That's a nice feature, thanks!
Three questions. Is it possible to:
1. get it to use the INNER JOIN and LEFT OUTER JOIN syntax instead of joining the tables in the WHERE clause?
2. control the table aliases so that it will automatically use the "standard alias" for the table instead of A, B, C, etc.?
3. get it to not put the schema name into the query?
Thanks!
Edited by: David Wendelken on Nov 22, 2008 1:48 PM. Grammar mistake.Hi Gopi,
Your code is Good.
But try to avoid Inner join with more number of Tables ...because this is a performance issue..
try to use..
select (primary key fields mainly,other fields) from LIKP into itab where bolnr in p_bolnr(paramater).
next try to use for all entries option..
select (primary key fields mainly,other fields) from VBFA for all entries in itab where (give the condition)....
simillarly do for the other select ....ok this will try to reduce the performance issue....
<b><REMOVED BY MODERATOR></b>
Message was edited by:
Alvaro Tejada Galindo -
hi all,
i m using inner join for 3 tables but problem is that i m getting repeated values while table contains only
2 record but inner joi shows me 4.
codes : SELECT m1pernr m2lgart m2endda m2betrg m2zuord m3lga01 m3bet01 m3begda INTO TABLE itab
FROM pa0000 AS m1 INNER JOIN pa0015 AS m2 ON m1pernr = m2pernr
INNER JOIN pa0589 AS m3 ON m1pernr = m3pernr
WHERE m1pernr IN pernr AND m1endda = '99991231' AND m1~stat2 = '3'
AND m2~lgart = '4004'
AND m3~lga01 = '4004'.
getting values in itab like :
PERNR LGART BETRG BET01
8430 4004 5834.00 5004.00
8430 4004 8748.00 5004.00
8430 4004 5834.00 1000.00
8430 4004 8748.00 1000.00
while it must be like this :
PERNR LGART BETRG BET01
8430 4004 5834.00 5004.00
8430 4004 8748.00 1000.00
can anyone please help me.
regards saurabh.Hello Saurabh,
Include all the primary key fields in the where clause for PA0015 and PA0589, while comparing with those in PA0000. Since the key fields for all these '3' tables are same this should not be a problem.
If you have any reservations about changing the select query, then, sort your final internal table with a defined sort key (based on your requirement) and use "Delete adjacent duplicates" with the same sort key.
Please let me know if this helps.
Regards,
Pavan -
Hi,
The following code works perfectly for me and give me a list of users for a specific OU and their respective logon types :-
$logFile = 'c:\test\test.txt'
$_myOU = "OU=ABC,dc=contosso,DC=com"
# LogonType as per technet
$_logontype = @{
2 = "Interactive"
3 = "Network"
4 = "Batch"
5 = "Service"
7 = "Unlock"
8 = "NetworkCleartext"
9 = "NewCredentials"
10 = "RemoteInteractive"
11 = "CachedInteractive"
Get-WinEvent -FilterXml "<QueryList><Query Id=""0"" Path=""Security""><Select Path=""Security"">*[System[(EventID=4624)]]</Select><Suppress Path=""Security"">*[EventData[Data[@Name=""SubjectLogonId""]=""0x0""
or Data[@Name=""TargetDomainName""]=""NT AUTHORITY"" or Data[@Name=""TargetDomainName""]=""Window Manager""]]</Suppress></Query></QueryList>" -ComputerName
"XYZ" | ForEach-Object {
#TargetUserSid
$_cur_OU = ([ADSI]"LDAP://<SID=$(($_.Properties[4]).Value.Value)>").distinguishedName
If ( $_cur_OU -like "*$_myOU" ) {
$_cur_OU
#LogonType
$_logontype[ [int] $_.Properties[8].Value ]
#Time-created
$_.TimeCreated
$_.Properties[18].Value
} >> $logFile
I am able to pipe the results to a file however, I would like to convert it to CSV/HTML When i try "convertto-HTML"
function it converts certain values . Also,
a) I would like to remove duplicate entries when the script runs only for that execution.
b) When the script is run, we may be able to search for records after the last run and not search in the same
records that we have looked into before.
PLEASE HELP !If you just want to look for the new events since the last run, I suggest to record the EventRecordID of the last event you parsed and use it as a reference in your filter. For example:
<QueryList>
<Query Id="0" Path="Security">
<Select Path="Security">*[System[(EventID=4624 and
EventRecordID>46452302)]]</Select>
<Suppress Path="Security">*[EventData[Data[@Name="SubjectLogonId"]="0x0" or Data[@Name="TargetDomainName"]="NT AUTHORITY" or Data[@Name="TargetDomainName"]="Window Manager"]]</Suppress>
</Query>
</QueryList>
That's this logic that the Server Manager of Windows Serve 2012 is using to save time, CPU and bandwidth. The problem is how to get that number and provide it to your next run. You can store in a file and read it at the beginning. If not found, you
can go through the all event list.
Let's say you store it in a simple text file, ref.txt
1234
At the beginning just read it.
Try {
$_intMyRef = [int] (Get-Content .\ref.txt)
Catch {
Write-Host "The reference EventRecordID cannot be found." -ForegroundColor Red
$_intMyRef = 0
This is very lazy check. You can do a proper parsing etc... That's a quick dirty way. If I can read
it and parse it as an integer, I use it. Else, I just set it to 0 meaning I'll collect all info.
Then include it in your filter. You Get-WinEvent becomes:
Get-WinEvent -FilterXml "<QueryList><Query Id=""0"" Path=""Security""><Select Path=""Security"">*[System[(EventID=4624 and EventRecordID>$_intMyRef)]]</Select><Suppress Path=""Security"">*[EventData[Data[@Name=""SubjectLogonId""]=""0x0"" or Data[@Name=""TargetDomainName""]=""NT AUTHORITY"" or Data[@Name=""TargetDomainName""]=""Window Manager""]]</Suppress></Query></QueryList>"
At the end of your script, store the last value you got into your ref.txt file. So you can for example get that info in the loop. Like:
$Result += $LogonRecord
$_intLastId = $Event.RecordId
And at the end:
Write-Output $_intLastId | Out-File .\ref.txt
Then next time you run it, it is just scanning the delta. Note that I prefer this versus the date filter in case of the machine wasn't active for long or in case of time sync issue which can sometimes mess up with the date based filters.
If you want to go for a date filtering, do it at the Get-WinEvent level, not in the Where-Object. If the query is local, it doesn't change much. But in remote system, it does the filter on the remote side therefore you're saving time and resources on your
side. So for example for the last 30 days, and if you want to use the XMLFilter parameter, you can use:
<QueryList>
<Query Id="0" Path="Security">
<Select Path="Security">*[System[TimeCreated[timediff(@SystemTime) <= 2592000000]]]</Select>
</Query>
</QueryList>
Then you can combine it, etc...
PS, I used the confusing underscores because I like it ;)
Note: Posts are provided “AS IS” without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. -
For All Entries is NOT better than INNER JOIN in most cases
I quote from Siegfried Boes' excellent post here: Will writing an inner join be better or creating a view?
For all the FOR ALL ENTRIES lovers ... there is no proof for these reappearing recommendation.
There is nearly nobody who receives forum points, who recommends FOR ALL ENTRIES instead of Joins. What is the reason ???
It is easier to prove the opposite. A Join is a nested loop inside the database, a FOR ALL ENTRIES is partly outside of the database. FOR ALL ENTRIES works in blocks, joins on totals.
FOR ALL ENTRIES are not recommded on really large tables, because the chances are too high that
too many records are transferred.
People prefer FOR ALL ENTRIES, because JOINs are not so easy to understand. Joins can go wrong, but with a bit of understanding they can be fixed.
Some Joins are slow and can not be fixed, but then the FOR ALL ENTRIES would be extremely slow.
There are several kinds of views:
- projection views, i.e. only one table involved just fields reduced
- join views, several tables, joins conditions stored in dictionary
- materialized views, here the joined data are actually stored in the database. Storing and synchronisation has to be done manually.
Only the last one creates real overhead. It should be the exception.
Join Views and Joins are nearly identical. The view is better for reuse. The join is better in complicated, becuase if the access goes wrong, it can often be fixed by adding a hint. Hints can not be added to views.
Abraham Bukit points out:
If it is cluster table, (you can't use join). If it is buffered table, I would also say avoid join.
If they all are transaction table which are not buffered and are not cluster tables.
He further supports Siegfried's statement that FAE is easier to undestand than INNER JOINs.
Thomas Zloch says, regarding buffered tables:
At least think twice, maybe compare runtimes if in doubt.
So, unless someone has some EVIDENCE that FOR ALL ENTRIES is better, I don't think we want to see this discussed further.
Kind regards
MattTo give food for thought here's an example I gave in a thread:
If you have a statement like
SELECT ... FOR ALL ENTRIES IN FAE_itab WHERE f = FAE_itab-f.
SAP sends it to the database depending how the parameter rsdb/prefer_union_all is set:
rsdb/prefer_union_all = 0 =>
SELECT ... WHERE f = FAE_itab[1]-f
OR f = FAE_itab[2]-f
OR f = FAE_itab[N]-f
You have some influence of the generated statement type: Instead of OR'ed fields an IN list can be used
if you have only a single coulmn N to compare:
rsdb/prefer_in_itab_opt parameter:
SELECT ... WHERE f IN (itab[1]-f, itab[2]-f, ..., itab[N]-f)
rsdb/prefer_union_all = 1 =>
SELECT ... WHERE f = FAE_itab[1]-f
UNION ALL SELECT ... WHERE f = FAE_itab[2]-f
UNION ALL SELECT ... WHERE f = FAE_itab[N]-f
see: Note 48230 - Parameters for the SELECT ... FOR ALL ENTRIES statement
As you can see for the 2nd parameter several statements are generated and combined with a UNION ALL,
the first setting generates statements with OR's (or uses IN if possible) for the entries in FAE_itab.
I give you a little example here (my parameters are set in a way that the OR's are translated to IN lists; i traced the execution in ST05)
Select myid into table t_tabcount from mydbtable
for all entries in t_table " 484 entries
where myid = t_table-myid .
ST05 trace:
|Transaction SEU_INT|Work process no 0|Proc.type DIA|Client 200|User |
|Duration |Obj. name |Op. |Recs.|RC |Statement|
| 640|mydbtable |PREPARE| | 0|SELECT WHERE "myid" IN ( :A0 , :A1 , :A2 , :A3 , :A4 ) AND "myid" = :A5|
| 2|mydbtable |OPEN | | 0|SELECT WHERE "myid" IN ( 1 , 2 , 3 , 4 , 5 ) AND "myid" = 72 |
| 2.536|mydbtable |FETCH | 0| 1403| |
| 3|mydbtable |REOPEN | | 0|SELECT WHERE "myid" IN ( 6 , 7 , 8 , 9 , 10 ) AND "myid" = 72 |
| 118|mydbtable |FETCH | 0| |
| 2|mydbtable |REOPEN | | 0|SELECT WHERE "myid" IN ( 11 , 12 , 13 , 14 , 15 ) AND "myid" = 72 |
| 3|mydbtable |REOPEN | | 0|SELECT WHERE "myid" IN ( 475 , 476 , 477 , 478 , 479 ) AND "myid" = 72 |
| 94|mydbtable |FETCH | 0| 1403| |
| 2|mydbtable |REOPEN | | 0|SELECT WHERE "myid" IN ( 480 , 481 , 482 , 483 , 484 ) AND "myid" = 72 |
You see the IN list contained 5 entries each , wich made up about 97 statements for all 484 entries.
For every statment you have a single fetch operation wich means a separate access to the database.
If you would replace the FAE with a join you would only have one fetch to the database.
With the example above we can derive these observations:
1. From database point of view these settings kill performance when you access a big table and/or have a lot of entries or columns in your FAE_itab. Furthermore, you hide information what data you will access
at all and thus you block the database from creating a more efficient execution plan because it DOESN'T KNOW wich data you will select in the next step. I.e. it may be more efficient to scan the table in one shot instead of having many index accesses - but the database can make this decision only if it can examine ONE statement that has ALL the information of what data to retrieve.
2. A second impact is that with every statement execution you trigger the allocation of database resources
wich will contribute to the overhead described above.
Said that, FAE can never be a replacement for joining big tables (think of having a table with thousands of records in a FAE table )
Edited by: kishan P on Nov 2, 2010 2:16 PM - Format Fixed
Maybe you are looking for
-
Is it possible to make an iframe full size to the browser inside muse , if using insert htm
using iframe code , it is coming in a small box want to use it to full browser
-
hi i have this table leadtbl ==== Fname | Lcode | goods ============== AAA | 51 | XXX AAA | 51 | DDD AAA | 51 | FFF AAA | 62 | EEE AAA | 73 | PPP BBB | 21 | CCC BBB | 32 | S
-
Transfer IDOC types to client server
Hi Experts, I am creating IDOC types on our sandbox server for some integration testing with XI sandbox server. After successful testing we need to replicate all IDOC types/ messages and partner profile settings to the client server so that data can
-
ITunes 8 always opens when I log in/restart
Ever since I updated to iTunes 8 it always opens upon restart/startup or log in.. how can I make it not do that? THANKS!!
-
Any way to obtain replacement copy of CS2?
Migrated to a new PC...trouble is, I cannot find my copy of CS2 to install on new machine. It was actually an upgrade from CS that I had downloaded...somewhere...I called Adobe and was told they cannot supply a replacementI would need to upgrade to C