Query and sort content from two lists using search API

Hi,
I have a custom web part which I would like to query two different lists and sort the results by Created Date. One is a list of news articles and the other contains blogs. So basically the result set will be an intermix of news and blog items sorted by date.
I would also like to do this by query through the search API. Does anybody have any sample code to do this?
thanks,
Sherazad.
Sherazad

Hi Sherazad:
To use the JOIN operator in CAML, your lists must have a
defined relation(Lookup column). You can refer to sample code that I list as follow.
Create your query from one of your lists.
SPList Projects= SPContext.Current.Site.RootWeb.Lists["Projects"];
SPQuery query = new SPQuery();
To do the join, setquery.Joins
 <Join Type="INNER" ListAlias="Contacts">
    <Eq>
        <FieldRef Name="ProjectManager" RefType="ID" /> ///
ProjectManager is a Lookup Column.
        <FieldRef List="Contacts" Name="ID" />
    </Eq>
 </Join>
And query.ProjectedFields (To tell SharePoint how to project the lookup columns into the result)
<Field Name="Project Name" Type="Lookup" List="Projects" ShowField="Title">
/// My Project Name is a Display Name in Memory so you can give a name by yourself But ShowField must be Internal Name of the Column(Project Name)
You can add a lot of columns that you want to display.
Everything comes from memory.
To choose the fields to display set query.ViewFields
<FieldRef Name="Your Internal Name of Column Or
ProjectedFields - Field Name">
<FieldRef Name="Your Internal Name of Column Or
ProjectedFields - Field Name">
<FieldRef Name="Your Internal Name of Column Or
ProjectedFields - Field Name"> 
Then
SPListItemCollection result = ListA.GetItems(query);

Similar Messages

  • Lightroom not merging and sorting images from two different cameras - help please !!

    Hi guys,
    I need some help here. I've just imported a few thousands of images form two different cameras, however Lightroom simply sorts them by camera only. (i.e.. images from the first camera, all sorted by capture time, then come images form the second camera.)
    The cameras are the same brand and model, times are synchronised, but the images refuse to merge and sort. I've tried putting them in the same folder and importing, but that doesn't do it either. I've been doing this for years and it all worked fine, till today. Does anyone know whats causing this, and how I can fix it?
    Thanks in anticipation.
    Latch

    Hi John,
    View > Sort > Capture Time is checked, The cameras are in sync down to the second, and images from both have been merging and sorting fine for over two years, till today. Sort order is all set to capture time in all modes and views, but its still sorting first by camera.

  • Sort numbers from two lists

    Hello,
    I have two ordered lists LIST1 and LIST2 which elements are composed
    of a field named "value" (an integer number) and a field named "prox"
    that points on the following element ("nil" when there aren't new
    elements).
    The elements are disposes in each list in crescent order of value.
    What's the optimal Java algorithm to print in crescent order the
    combination of the elements of both lists?
    For example, if the first list is formed by values 8, 12, 13, 28, and
    the second by values 10, 11, 35, it must print the list 8, 10, 11, 12,
    13, 28, 35.
    Thanks in advance to all
    Dario

    Hello,
    I have two ordered lists LIST1 and LIST2 which
    elements are composed
    of a field named "value" (an integer number) and a
    field named "prox"
    that points on the following element ("nil" when
    there aren't new
    elements).
    The elements are disposes in each list in crescent
    order of value.
    What's the optimal Java algorithm to print *in
    crescent order* the
    combination of the elements of both lists?
    For example, if the first list is formed by values 8,
    12, 13, 28, and
    the second by values 10, 11, 35, it must print the
    list 8, 10, 11, 12,
    13, 28, 35.
    Thanks in advance to all
    DarioPlease present your algorithm in the form of pseudocode and
    tell us where you have problem with Java.
    this will pinpoint your problem and hence you will get faster response.
    thanks

  • Creating a external content type for Read and Update data from two tables in sqlserver using sharepoint designer

    Hi
    how to create a external content type for  Read and Update data from two tables in  sqlserver using sharepoint designer 2010
    i created a bcs service using centraladministration site
    i have two tables in sqlserver
    1)Employee
    -empno
    -firstname
    -lastname
    2)EmpDepartment
    -empno
    -deptno
    -location
    i want to just create a list to display employee details from two tables
    empid firstname deptno location
    and same time update  in two tables
    adil

    When I try to create an external content type based on a view (AdventureWorks2012.vSalesPerson) - I can display the data in an external list.  When I attempt to edit it, I get an error:
    External List fails when attached to a SQL view        
    Sorry, something went wrong
    Failed to update a list item for this external list based on the Entity (External Content Type) 'SalesForce' in EntityNamespace 'http://xxxxxxxx'. Details: The query against the database caused an error.
    I can edit the view in SQL Manager, so it seems strange that it fails.
    Any advice would be greatly GREATLY appreciated. 
    Thanks,
    Randy

  • I am trying to store music for two different iPods on the same computer, against two different Apple IDs. When I try and download content from the Cloud I get an error message?

    I am trying to store music for two different iPods on the same Windows 8 computer, and when I try and download content from the Cloud I get an error message. Is it possible to have two different Apple IDs on the same computer?

    Unfortunately you've discovered too late how important it is to maintain an up-to-date backup of your iTunes library (and all other data of value).  You could, before wiping the drive, have considered making use of a commercial data recovery service that could (albeit at considerable cost) have extracted your library from the hard disk, even if virus infected.
    In the absence of that option, you will need to restore the content of your library from its original sources:
    Depending on your location, you may be able to re-download any iTunes Store purchases that are still available on the Store
    Likewise, most digital purchases from Amazon (including auto-rip copies of purchased CDs) should be available from the Amazon Cloud and via the Amazon Music application - the same may be true of other commercial sources for digital downloads
    Content imported from your CDs will have to imported again
    The specific situation that you describe regarding the music imported from your friend's external HDD suggests that either the source is badly organized and/or originates from a source other than iTunes (other media players may use alternative tags for information like artist, title, album, etc. that are not wholly consistent with how iTunes handle these).  Without details of the issues you're seeing it is difficult to suggest a remedy other than going through the media album-by-album, track-by-track, and correcting the inconsistencies.
    In the absence of a backup or access to the original library data there is no option other than painstakingly recreating your library as described above.  As you do so, you'll now realize how important creating and maintaining backups are - in my case I have at all times three separate duplicates of my library, in two different locations, where none is ever more than a week old compared to the content of my master library.

  • From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?

    From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?

    Hi,
    Use NVL or COALESCE:
    NVL (col_a, col_b)
    Returns col_a if col_a is not NULL; otherwise, it returns col_b.
    Col_a and col_b must have similar (if not identical) datatypes; for example, if col_a is a DATE, then col_b can be another DATE or it can be a TIMESTAMP, but it can't be a VARCHAR2.
    For more about NVL and COALESCE, see the SQL Language manual: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions119.htm#sthref1310
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • I am used to "drag and drop" content from my computer to my old i-pod.  With the new i-tunes, I can't seem to do that.  Any suggestions?

       I am used to "drap and drop" content from my computer to my old i-pod.  With the new i-tunes, I can't seem able to do that.  Any suggestions?  Thanks.

    diana42 wrote:
    My problem is that Itunes does not acknowledge inserted CD in DEVICES area,
    Are these Audio CDs?
    Only Audio CDs will show up in iTunes.
    This is new to me because I am used to importing and making copies from my playlists.
    I don't follow. Would you explain this a bit more?

  • Showing updated items from two lists ?

    Hi SharePoint Experts,
    I have created two custom lists in top level site, For accomplishing my task, I have used DataView to show all items from the two lists order by modify. Of course, this DataView webpart showing data but which is not in proper way.
    And also show status column from workflow which is actually from different groups.
    Is dashboards  suitable to my task? Is dashboards capable to show data from two list ? also status column from workflow.
    Appreciate if any suggestions..
    Thank you.

    Hi,
    As you are using SharePoint 2013 you can use the Content search web part to display the data from multiple list.
    Please refer to the similar post, which has detailed steps how to use the content search web part.
    http://sharepoint.stackexchange.com/questions/112085/how-to-get-data-from-multiple-table-or-list-in-sharepoint-2013
    If you still persists to use the Dataview web part, please refer to the following article.
    http://sp2013.blogspot.de/2013/11/two-sharepoint-lists-in-dataview-linked.html
    Please don't forget to mark it as answered, if your problem resolved or helpful.

  • How to remove a Sort button from ALV List

    Hi Experts,
    How to remove sort button from ALV List.
    I have requirement where I need to remove the sort button from ALV list.
    Kindly give me useful clues.
    Higher points will be awarded for the useful inputs.
    Thanks in Advance,
    Dharani

    Hi dharani,
    1. UP and Down Sort Button will get removed.
    2. Important code is marked in bold
    3. Just copy paste.
    4.
    report abc.
    TYPE-POOLS : slis.
    DATA : alvfc TYPE slis_t_fieldcat_alv.
    DATA : alvfcwa TYPE slis_fieldcat_alv.
    <b>data : excl type SLIS_T_EXTAB.
    data : exclwa type SLIS_EXTAB.</b>
    data : begin of itab occurs 0.
            include structure usr02.
    data : end of itab.
    START-OF-SELECTION.
      select * from usr02
      into table itab.
      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
        EXPORTING
          i_program_name         = sy-repid
          i_internal_tabname     = 'ITAB'
          i_inclname             = sy-repid
        CHANGING
          ct_fieldcat            = alvfc
        EXCEPTIONS
          inconsistent_interface = 1
          program_error          = 2
          OTHERS                 = 3.
    <b>*----
    IMPORTANT
    fcodes to remove
    Up and Down Sort Button
    exclwa-fcode = '&OUP'.
    append exclwa to excl.
    exclwa-fcode = '&ODN'.
    append exclwa to excl.</b>
    Display
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
          it_fieldcat   = alvfc
          <b>IT_EXCLUDING     = excl</b>
        TABLES
          t_outtab      = itab
        EXCEPTIONS
          program_error = 1
          OTHERS        = 2.
    regards,
    amit m.

  • How to save, update and retrieve data from two diffrent table

    Hi,
    I can save and retrieve data into an user defined SBO form from one database table only. How can I save retrieve and update records from two or more different tables in a single screen?
    Regards,
    Sudeshna.

    Sudeshna,
    Are these tables external to SAP Business One and do not have a Business Object?  If there is a Business Object available such as if you were to enter an order, that order would use the Documents object which abstracts you, the programmer, from the underlying tables that need to be updated.  If you are handling multiple business objects you would need to wrap the transaction with the StartTransaction - EndTransaction methods.  This information is detailed in the SAP Business One SDK Help Center that comes with the SDK.
    HTH,
    Eddy

  • How do I hide my mailbox and mail contents from other users, leaving other functions of my iMac accessible?

    How do I hide my mailbox and mail contents from other users, leaving other functions of my iMac accessible?

    You don't have to shut down the computer to switch accounts. All you do is click the Apple symbol in the upper left and choose Log Out and that's it. You can also set up Faster User Switching by:
    1. Open System Preferences - Accounts
    2. Click Login Options
    3. Check the box called "Show fast user switching menu as" then choose from either icon, short name or name.
    Then when someone wants to switch users they can. The advantage of this method is if you are have a document open and don't want to close it the document will remain open. If the other user attempts to shut down the computer they can't until you have logged out thereby saving all your data.
    A very simple and elegant solution.

  • HT1918 I tried to sign for Course Manager and I am from Taiwan cannot use it why? its horrible it should be international here in Taiwan everybody also uses English too.. Apple should understand it very well.

    I tried to sign for Course Manager and I am from Taiwan cannot use it why? its horrible it should be international here in Taiwan everybody also uses English too.. Apple should understand it very well.  Can anybody guide how can I do or sign inot Course Manager as I am an English teacher here in Taiwan and not able to access the software or Apps because its says TAIWAN NOT AVAILABLE I THINK ITS NOT FAIR AT ALL AFTER SPENDING SO MUCH MONEY ON MY NEW IPAD 64GB

    Licensing restrictions or issues.

  • TS4062 I am trying to transfer my purchased and uploaded content from my IPhone 4S to my ITunes account on my laptop.  When i try to sync, it wants to wipe out my phone content with what is on my computer which has nothing.  Am i missing something?

    I am trying to sync my iphone 4s to my windowns Itunes account.  When i try to do it, the sync wants to remove all of the content on my phone and replace it with what is on my laptop, which has nothing yet.  I am trying to move all of my purchased and uploaded content from my phone to the computer, but don't see the setting to do that.

    Have you tried contactint the app's developer?

  • HT5661 If I reset and erase contents from my old iphone as suggested, will it effect my new iphone that I have already transferred my data to? Do I need to turn off Icloud on old phone before erasing data ?

    If I reset and erase contents from my old iphone will it effect the data I have already transferred to my ne iphone?

    Hello ski12
    Restoring or erasing all content and settings will just turn the feature of iCloud off and not deleting from iCloud. If you want to, turn off iCloud before you go through with erasing it.
    iCloud: Change iCloud feature settings
    http://support.apple.com/kb/PH2613
    Regards,
    -Norm G.

  • How do I remove this certain instance of Google search from my list of search bars?

    Recently, I decided to try a different search engine in place of Google, which I removed from my list of search engines in the search bar via Manage Search Engines. Dissatisfied with this search engine, I decided to switch back, using an add-on called Add to Search Bar. However, this disables the autocomplete feature for that search engine. I was able to get the autocomplete feature back by restoring the default search engines in the Manage Search Engines menu. However, now I can't remove the instance of Google's search engine which I installed with the add-on. When I remove it, the OK button becomes unresponsive and I'm forced to cancel.
    Add to Search Bar
    https://addons.mozilla.org/en-US/firefox/addon/add-to-search-bar/
    I don't have any trouble deleting other search engines installed by this add-on, other than this Google one.
    The .xml file for this search engine doesn't appear in the searchplugins folder in my profile folder.

    Try to delete search.json file and a possible search.sqlite file in the Firefox Profile Folder.
    *http://kb.mozillazine.org/Profile_folder_-_Firefox
    *http://kb.mozillazine.org/Unable_to_search_or_add_new_engines

Maybe you are looking for

  • I have multiple imap accounts on thunderbird, but the last two accounts will not show messages in the inbox.

    I have 7 imap accounts some with several subscribed folders. One is a gmail account. The others are from a personal .com. Everything works fine, including the gmail, except the last two accounts added will not sync the inboxes. The sent boxes sync fi

  • Landscape mode whether I like it or not

    Whenever I start Safari and am holding the phone upright(not sideways) Safari starts for a second in portrait mode and then automatically flips to landscape even though I haven't turned the phone. Also when I enter the music player it briefly(1 sec)

  • Reg:SAP GEM add on

    Hi experts, I have a requirement to imlpement the add on SAP GEM(Global Employee Management it is a SAP HR sub module)  in our production environment. Currently we are on ECC6.0 with SAPHR-SAPKE60028 and EA HR-SAPKGPHD17 levels. Can some pls.let me k

  • Down Arrow after zoom

    If I zoom with the mouse scroll "alt scroll" then press the down arrow it opens my file menu, this is 100% reproducable. Zoom any other way will not open the menu. I have searched the shortcuts and can not find any shortcut associated with opening th

  • How can I download eBooks to multiple iPads using same apple ID?

    How can I download eBooks to multiple iPads using the same apple ID?