Joining two lists
Hi,
Let's say I have a class Car
public class Car{
private int id;
private String make;
private String model;
//getters and setters
}Now I'm going to some db and fill a List<Car>,
List<Car> results1 = getCarsFromDB(String someCriteria);and I do the same but this time I'm going to another db,
List<Car> results2 = getCarsFromAnotherDB(String someCriteria);What I want is to create a list with the two results lists. Using contains method from List doesn't work because the objects are different although the have the same data. Is there a simple way of joining this? (in my example, two objects are equal if they have the same idthanks in advance,
Manuel Leiria
ok, I have now an equals and hashCode method in my
Car but I can't see how the Collections.addAll can
help me! When joining the two lists in a resultlist,
at some point I must compare the Car objects. Am I
wrong?
thanks,
Manuel leiriaso if I understand you, you're trying to merge 2
collections, and avoid duplicates? sounds like a job
for Sets, then!yes, I've changed my final list to a set. It's better
thanks,
Manuel Leiria
Similar Messages
-
Join two list with condition using caml query in SharePoint 2013 with client object model
Hi,
Want to join two list to get all fields from both list.
Am new to sharepoint and sharepoint 2013. Am working in sharepoint 2013 online apps. Am using context.executeQueryasync to load list and get items from list. Am able to get items from single list with caml query, but not able to get both list field values
with joins. I did lot of surfing..but not..
Below is my code..
ListName1 : "AssignedTasks"
ListName2 : "Tasks"
var assignedQueryTest = "<View><Joins><Join Type='INNER' ListAlias='Tasks'><Eq><FieldRef Name='TaskId' RefType='Id'/><FieldRef List='Tasks' Name='ID' /></Eq></Join></Joins>"
+ "<ViewFields><FieldRef Name='TitleValue' /><FieldRef Name='ActionItemsValue' /></ViewFields>"
+ "<ProjectedFields>"
+ "<Field Name='TitleValue' Type='Lookup' List='Tasks' ShowField='Title' /><Field Name='ActionItemsValue' Type='Lookup' List='Tasks' ShowField='ActionItems' />"
+ "</ProjectedFields>"
+ "</View>";
var web = context.get_web();
var list = web.get_lists().getByTitle("AssingedTasks");
var myQuery = new SP.CamlQuery();
myQuery.set_viewXml(assignedQueryTest);
var myItems = list.getItems(myQuery, "Include(TitleValue,ActionItemsValue)");
context.load(myItems);
context.executeQueryAsync(function () { if(myItems.get_count()>0){....}
}, errorCallback);
Here am able to get "AssignedTasks" list field values but not able to get "Tasks" list field values.
Can you please help me to resolve the issue. Or new idea for join. I have add the condition also in the query.
If anybody have good sample, please provide.
Thanks,
Pariventhan
Pariventhan.SHi Pariventhan,
I don't know about join but I have a workaround of this problem.
Declare one variable (itemcollection) globally. Load all the items "AssignedTasks" using context.load.
In the success method call another CAML query using <IN> tag of the ID of the items from the second list (Assuming you have look-up column of the ID of the first list to the second list).
If this is not clear to you then please let me know. If possible then I can provide code sample.
Thanks,
Aniruddha -
How to join two lists and display the results in datasheet view.?
hello,
i have two lists that i would like to join, i know a method that has been described in the link below
http://www.codeproject.com/Articles/194252/How-to-Link-Two-Lists-and-Create-a-Combined-Ciew-i
however, here the data view is only limited to 30 rows and my resultant list is huge. I would like to know if there is a possibility to view the resultant list in a data sheet view ?I don't believe you can use the OOTB Datasheet view when joining lists. However, you should be able to increase your limit from 30 items to as many as you need (that doesn't trip the threshold set in Central Admin).
Dimitri Ayrapetov (MCSE: SharePoint) -
Join two list of integer type field using CAML query
Hi
As i am struggling in Join two sharepoint list (Roles and Emplyees). As there is no lookup columns and lists are already existing and have almost 3000 + recodrs. As a part of enhancement work need to join these list. List structure is some thing as follows:
Roles :
ID Title
1 Project Manager
2 Business Analyst
3 Developer
Employees :
Name Role
1 James 1
2 Petar 3
3 John 2
Output should be like as follows:
Name Role
1 James Project Manager
2 Petar Developer
3 John Developer
So please suggest, if the joining can be done other than lookup columns through the CAML query.
Akhilesh RaoFollow below CAML query to add joins between two lists.
SPList list = SPContext.Current.Site.RootWeb.Lists["Employees"];
SPQuery query = new SPQuery();
query.Joins = @" <Join Type="INNER" ListAlias="Roles">
<Eq>
<FieldRef Name="Employees" RefType="Role" />
<FieldRef List="Roles" Name="ID" />
</Eq>
</Join>";
query.ProjectedFields = @" <Field Name="RoleName" Type="Lookup" List="Roles" ShowField="Title">";
query.ViewFields = @ "<FieldRef Name="Title">
<FieldRef Name="RoleName"> ";
SPListItemCollection result = tablea.GetItems(query);
Adnan Amin MCT, SharePoint Architect | If you find this post useful kindly please mark it as an answer :) -
How to join two lists in third?
I have a 2 lists of one type elements:
List1 contain: P1, P2
<List1>
<string>P1</string>
<string>P2</string>
</List1>
List2 contain: P2, P3, P4
<List2>
<string>P2</string>
<string>P3</string>
<string>P4</string>
</List2>
I need this elements in List3, without repeatings (like "select distinct" in sql) .
So, I need to get a List3 equals: P1, P2, P3, P4
<List3>
<string>P1</string>
<string>P2</string>
<string>P3</string>
<string>P4</string>
</List3>
How to achieve this?
I think its possible with Transformation, but what kind of function i need to use in it?One option would be to use this approach:
1. Copy List1 to Output variable
2. Loop over elements in List2
3. If element in List 2 does not exist in List1 add it to output variable
Problem might be performance if you have long lists. It's easy to write it using BPEL activities. I think this could be written also in XSL.
Regards,
Milan -
Can i join a list in sub-site using Join query?
Hi all,
I'm newbie and i have tried to join a list in parent site with a list in sub-site using Join query but i always get the error. How can i do this action? Thanks!You could try using SPSiteDataQuery or a DataTable.
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsitedataquery%28v=office.14%29.aspx
http://sharepoint.stackexchange.com/questions/75713/is-it-possible-to-populate-result-by-joining-two-lists-throughout-the-site-colle
--Cheers -
The order doesn't work in my view with join between two lists. And now?
Hi,
I work with sharepoint 2010.
I did the join between two list follow this
post.
I did it and everything is ok, but the order doesn't work.
What can be it?
Thanks
K2rto'4 - Analista Sharepoint
"Hoje melhor do que ontem, amanhã melhor do que hoje!" 改 善Hi,
I've two lists in my view with join. The list A and the list B.
I'm ordering the view with the column list A.
The column list A it's a column for type lookup to list B's column.
In my view i'm ordering with the column list A of type lookup.
The view with join is not ordering in order growing.
I want the view will be ordering by order growing.
Do you understood?
Hugs
K2rto'4 - Analista Sharepoint
"Hoje melhor do que ontem, amanhã melhor do que hoje!" 改 善 -
Export to Excel - two lists into 1 Excel table
Hello SharePoint experts,
I have two lists with the exact same columns of data. The reason I have two lists is because they each represent a single year of data where the list contains 5,000+ items. We found we had
to "archive" old year items into a new list, otherwise we were not able to appropriately export to Excel (it wouldn't work) as well as make updates to the InfoPath from when the count was too high.
These lists are exported into Excel to leverage pivot tables and run metrics based on the data in the lists. I can bring both data connections into the same Excel file, but I am not sure if
there is a way to merge the lists so I can simply apply a filter to the pivot tables to select the appropriate year.
Any input is greatly appreciated.
Mark G.
MGIf you have both data connection files, I think you just need to make a join/merge. I think this may help:
http://office.microsoft.com/en-us/excel-help/combine-data-from-multiple-data-sources-HA103993145.aspx
Andy Wessendorf SharePoint Developer II | Rackspace [email protected] -
hi
how to join two tables using inner join if the first table has two primary keys and second table has 3 primary keysWould describe type of joins in ABAP, which might differ with other joins.
The join syntax represents a recursively nestable join expression. A join expression consists of a left-hand and a right- hand side, which are joined either by means of INNER JOIN or LEFT OUTER JOIN. Depending on the type of join, a join expression can be either an inner (INNER) or an outer (LEFT OUTER) join. Every join expression can be enclosed in round brackets. If a join expression is used, the SELECT command circumvents SAP buffering.
On the left-hand side, either a single database table, a view dbtab_left, or a join expression join can be specified. On the right-hand side, a single database table or a view dbtab_right as well as join conditions join_cond can be specified after ON. In this way, a maximum of 24 join expressions that join 25 database tables or views with each other can be specified after FROM.
AS can be used to specify an alternative table name tabalias for each of the specified database table names or for every view. A database table or a view can occur multiple times within a join expression and, in this case, have various alternative names.
The syntax of the join conditions join_cond is the same as that of the sql_cond conditions after the addition WHERE, with the following differences:
At least one comparison must be specified after ON.
Individual comparisons may be joined using AND only.
All comparisons must contain a column in the database table or the view dbtab_right on the right-hand side as an operand.
The following additions not be used: NOT, LIKE, IN.
No sub-queries may be used.
For outer joins, only equality comparisons (=, EQ) are possible.
If an outer join occurs after FROM, the join condition of every join expression must contain at least one comparison between columns on the left-hand and the right-hand side.
In outer joins, all comparisons that contain columns as operands in the database table or the view dbtab_right on the right-hand side must be specified in the corresponding join condition. In the WHERE condition of the same SELECT command, these columns are not allowed as operands.
Resulting set for inner join
The inner join joins the columns of every selected line on the left- hand side with the columns of all lines on the right-hand side that jointly fulfil the join_cond condition. A line in the resulting set is created for every such line on the right-hand side. The content of the column on the left-hand side may be duplicated in this case. If none of the lines on the right-hand side fulfils the join_cond condition, no line is created in the resulting set.
Resulting set for outer join
The outer join basically creates the same resulting set as the inner join, with the difference that at least one line is created in the resulting set for every selected line on the left-hand side, even if no line on the right-hand side fulfils the join_cond condition. The columns on the right-hand side that do not fulfil the join_cond condition are filled with null values.
Note
If the same column name occurs in several database tables in a join expression, they have to be identified in all remaining additions of the SELECT statement by using the column selector ~.
Example
Join the columns carrname, connid, fldate of the database tables scarr, spfli and sflight by means of two inner joins. A list is created of the flights from p_cityfr to p_cityto. Alternative names are used for every table.
PARAMETERS: p_cityfr TYPE spfli-cityfrom,
p_cityto TYPE spfli-cityto.
DATA: BEGIN OF wa,
fldate TYPE sflight-fldate,
carrname TYPE scarr-carrname,
connid TYPE spfli-connid,
END OF wa.
DATA itab LIKE SORTED TABLE OF wa
WITH UNIQUE KEY fldate carrname connid.
SELECT ccarrname pconnid f~fldate
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ( ( scarr AS c
INNER JOIN spfli AS p ON pcarrid = ccarrid
AND p~cityfrom = p_cityfr
AND p~cityto = p_cityto )
INNER JOIN sflight AS f ON fcarrid = pcarrid
AND fconnid = pconnid ).
LOOP AT itab INTO wa.
WRITE: / wa-fldate, wa-carrname, wa-connid.
ENDLOOP.
Example
Join the columns carrid, carrname and connid of the database tables scarr and spfli using an outer join. The column connid is set to the null value for all flights that do not fly from p_cityfr. This null value is then converted to the appropriate initial value when it is transferred to the assigned data object. The LOOP returns all airlines that do not fly from p_cityfr.
PARAMETERS p_cityfr TYPE spfli-cityfrom.
DATA: BEGIN OF wa,
carrid TYPE scarr-carrid,
carrname TYPE scarr-carrname,
connid TYPE spfli-connid,
END OF wa,
itab LIKE SORTED TABLE OF wa
WITH NON-UNIQUE KEY carrid.
SELECT scarrid scarrname p~connid
INTO CORRESPONDING FIELDS OF TABLE itab
FROM scarr AS s
LEFT OUTER JOIN spfli AS p ON scarrid = pcarrid
AND p~cityfrom = p_cityfr.
LOOP AT itab INTO wa.
IF wa-connid = '0000'.
WRITE: / wa-carrid, wa-carrname.
ENDIF.
ENDLOOP. -
SharePoint list 2013 : Join 2 lists and combine into one view
Hi
I have created 2 custom list (say List A and List B) with few columns. I mapped the the default ID column from List A to List B by creating the lookup column(i.e List B :TestID; List A: ID). I want to programmatically combine these two lists
without using the additional lookup fields like what they explained in
http://blogs.msdn.com/b/kaevans/archive/2012/01/20/sharepoint-2010-caml-list-joins.aspx
also not using Linked DataSource in Sharepoint Designer
How to achieve this ?
Regards
SivaYou can do query in multiple list using Joins in CAML Query. check below example:
Created two list Markmaster and StudentMaster, both are connected with a lookup column(StudentID). Requirement is to fetch data from both the list.
StudentMaster List Column are StudentID, Name, Class, SEction, RoleNumber
MarksMaster List Column are ID, Title, ScienceGroup, ArtGroup, CommerceGroup, StudentID(Lookup of Studentmaster List but it is not necessary to be a lookup field, it can be a number field)
SPQuery query = new SPQuery();
SPList customerList = Oweb.Lists["MarksMaster"];
query.Query = @"<Query><Where><Neq><FieldRef Name='ID' /><Value Type='Counter'>null</Value></Neq></Where></Query>";
query.Joins = @"<Join Type='Left' ListAlias='StudentMaster'>
<Eq>
<FieldRef Name='StudentID' RefType='ID'/>
<FieldRef List='MarksMaster' Name='ID'/>
</Eq>
</Join>";
query.ProjectedFields = @"<field Name='StudentName' Type='Lookup' List='StudentMaster' ShowField='Title'/>
<field Name='StudentSection' Type='Lookup' List='StudentMaster' ShowField='Section'/> ";
query.ViewFields = @"<FieldRef Name='StudentName'/>
<FieldRef Name='StudentSection'/>
<FieldRef Name='ScienceGroup'/>";
Adnan Amin MCT, SharePoint Architect | If you find this post useful kindly please mark it as an answer. -
Problem encountered when join two remote tables in a materialized view
I'm using oracle 9.2.0.6
1> I have two tables:
CREATE TABLE TEST
A VARCHAR2(100 BYTE),
C DATE
CREATE TABLE TEST1
A VARCHAR2(100 BYTE),
B TIMESTAMP
2>. I defined a prebuild table:
CREATE TABLE MV_TEST1
ID1 ROWID,
A VARCHAR2(100 BYTE),
ID2 ROWID,
B TIMESTAMP(6),
C DATE
3> I created mview logs:
CREATE MATERIALIZED VIEW LOG ON PSI_TEST.TEST
WITH ROWID
INCLUDING NEW VALUES;
CREATE MATERIALIZED VIEW LOG ON PSI_TEST.TEST1
WITH ROWID
INCLUDING NEW VALUES;
4> when I create mview:
CREATE MATERIALIZED VIEW PSI_TEST.MV_TEST1
ON PREBUILT TABLE WITH REDUCED PRECISION
REFRESH FAST ON DEMAND
WITH PRIMARY KEY
AS
select
test.rowid id1,
test.a,
test1.rowid id2,
test1.b,
cast(null as date) c
from test , test1
where test.a = test1.a(+);
It is created successfully.
5> problem:
when I use remote tables to do the same thing, say test and test1 are in another instance and are connected by a dbLink, I couldn't create the mview successfully:
CREATE MATERIALIZED VIEW PSI_TEST.MV_TEST1
ON PREBUILT TABLE WITH REDUCED PRECISION
REFRESH FAST ON DEMAND
WITH PRIMARY KEY
AS
select
a.rowid id1,
a.a,
b.rowid id2,
b.b,
cast(null as date) c
from test@dbl a, test1@dbl b
where a.a = b.a(+);
when run above statement, I got:
ORA-12015: cannot create a fast refresh materialized view from a complex query
Any ideas? Or joining two table through a dblink for a mview is not allowed at all?
Thanks in advance.No one has a clue?
Message was edited by:
lzhwxy -
I am trying to develop a query in MS Access 2010 to join two tables using three joins, one of which is a (between) date range. The tables are contained in Access. The reason
the tables are contained in access because they are imported from different ODBC warehouses and the data is formatted for uniformity. I believe this cannot be developed using MS Visual Query Designer. I think writing a query in SQL would be suiting this project.
ABCPART links to XYZPART. ABCSERIAL links to XYZSERIAL. ABCDATE links to (between) XYZDATE1 and ZYZDATE2.
[ABCTABLE]
ABCORDER
ABCPART
ABCSERIAL
ABCDATE
[ZYXTABLE]
XYZORDER
XYZPART
XYZSERIAL
XYZDATE1
XYZDATE2Thank you for the looking at the post. The actual table names are rather ambiguous. I renamed them so it would make more sense. I will explain more and give the actual names. What I do not have is the actual data in the table. That is something I don't have
on this computer. There are no "Null" fields in either of the tables.
This table has many orders (MSORDER) that need to match one order (GLORDER) in GLORDR. This is based on MSPART joined to GLPART, MSSERIAL joined to GLSERIAL, and MSOPNDATE joined if it falls between GLSTARTDATE and GLENDDATE.
[MSORDR]
MSORDER
MSPART
MSSERIAL
MSOPNDATE
11111111
4444444
55555
2/4/2015
22222222
6666666
11111
1/6/2015
33333333
6666666
11111
3/5/2015
This table has one order for every part number and every serial number.
[GLORDR]
GLORDER
GLPART
GLSERIAL
GLSTARTDATE
GLENDDATE
ABC11111
444444
55555
1/2/2015
4/4/2015
ABC22222
666666
11111
1/5/2015
4/10/2015
AAA11111
555555
22222
3/2/2015
4/10/2015
Post Query table
GLORDER
MSORDER
GLSTARTDATE
GLENDDATE
MSOPNDATE
ABC11111
11111111
1/2/2015
4/4/2015
2/4/2015
ABC22222
22222222
1/5/2015
4/10/2015
1/6/2015
ABC22222
33333333
1/5/2015
4/10/2015
3/5/2015
This is the SQL minus the between date join.
SELECT GLORDR.GLORDER, MSORDR.MSORDER, GLORDR.GLSTARTDATE, GLORDR.GLENDDATE, MSORDR.MSOPNDATE
FROM GLORDR INNER JOIN MSORDR ON (GLORDR.GLSERIAL = MSORDR.MSSERIAL) AND (GLORDR.GLPART = MSORDR.MSPART); -
We have tried joining two DSO's and are getting the warning that "more than one datasource has been used in this report". It appears that the DSO driver does not support joins. The report runs but it is VERY slow, the same sort of performance you get when you try to join data from two datasources that are actually different (like two different SQL Server databases or an Oracle table joined to a SQL Server table). It appears that this is not a supported function with the DSO driver. Any thoughts?
Yes, we have created the joins between the two DSOs. We are looking into using the Open SQL driver to go against the base tables to see if that will work. This is how the original ODS driver used to work.
Update: After changing the join type to a left outer join the performance improved signficantly. Although not ideal it looks like it will be fine for our requirements. This particular report will be run monthly and scheduled to run overnight.
Edited by: Mike Garrett on Oct 27, 2009 4:28 PM -
How to add two list in one frame using REUSE_ALV_LIST_DISPLAY
Hi,
I want to display two list in single output by calling FM 'REUSE_ALV_LIST_DISPLAY' twice.
I saw one topic posted by Arunava Das as 'ALV Problem' but didn't get the steps to do that.
Here is his way of doing that "What I have done is gone for the append ALV approach wher I have added the END_OF_LIST Event for the Fisrt reprt and in the Corresponding FORM Routine I have added another made another cALL to the REUSE_ALV_LIST DISPLAY FM with the other table."
I would be grateful if someone can help me out.Hi Ashish,
The way you have tried i.e. calling the second list in the END_OF_LIST event of first list and like wise that is the correct way of doing it.
Using this way you can display multiple lists. In the event END_OF_LIST by using a global variable G_COUNTER. the value of which you increment for each list and based on that counter you call different lists in the END_OF_LIST event.
case G_COUNTER.
when 1. perform call_first_list.
when 2. perform call_second_list.
when 3. perform call_third_list.
endcase.
Hope this answers your query
regards,
Satyadev Dutta -
Hi Sir/ Madam,
My name is Rishav and I am facing some problem with my Photoshop CC. Actually I have a question. If you guys could help me out i will be very obliged. The quest in "Can you please help me by saying me how can i join two different picture to make it as one picture.??"Maybe you should post over at
Photoshop for Beginners
or start with the "Get Started" section of the Help:
Photoshop Help | Photoshop Help
And your question
Can you please help me by saying me how can i join two different picture to make it as one picture.??
does not seem particularly specific – do you want to simply combine two images as they are, do you want to clip elements from the one and insert them into the other, …?
Could you post (lores of) the images and explain what you intend to achieve?
Maybe you are looking for
-
DVI to S-Video TV out no longer working
I have a Macbook Pro 2.4ghz Core 2 Duo, bought mid 2007. Up until December last year I have been able to use an Apple DVI to TV adapter to display on a TV. For some unknown reason this no longer works. To find a solution I have tried plugging things
-
URGENT: Selecting only 25 records at a time from a table
URGENT !!!! Hi, Im having a RFC which selects records from a table (say table_A) and depending on these selected records, further processing is done within that RFC. Now my problem is, this table_A contains around 200 matching records. Due to this en
-
Short Dump in BI 7.0,While Remodelling the Infocube
Hi Experts I got the below short dump in BI 7.0 while remodelling infocube to add a new time char (0CALMONTH2) Please update me what is wrong Runtime Errors GETWA_NOT_ASSIGNED Date and Time Short text Field symbol has not yet been as
-
HI.. Iam new in using ALV... this is the following report i created... When iam executing the following report its getting short dumped.. can anyone help me out in this... I didnt know how to use the FM reuse_alv_fieldcatalog_merge and iam facing pro
-
Typing Closes Programs - Help!
No idea what the **** is wrong with my MBP. It only started this issue today. Opened firefox and when i tried to type something in, it caused the program to crash. i thought it was an issue with firefox but the same happens with open.office and other