HOW TO SELECT ONLY THOSE RECORDS WHERE NOT AVAILABLE ON SECOND TABLE

hi
i have two tables one name is menus and second name is UGroupDetail. Actually i have created it for user role privileges for my application
USE [LedgerDB]
GO
/****** Object: Table [dbo].[Menus] Script Date: 03/28/2015 13:45:27 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Menus](
[RightID] [int] NOT NULL,
[RightName] [nvarchar](200) NULL,
[GroupID] [int] NULL,
CONSTRAINT [PK_Menus] PRIMARY KEY CLUSTERED
[RightID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
second table is
USE [LedgerDB]
GO
/****** Object: Table [dbo].[UGroupDetail] Script Date: 03/28/2015 13:46:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UGroupDetail](
[RightID] [int] NOT NULL,
[RightName] [nvarchar](200) NULL,
[GroupID] [int] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[UGroupDetail] WITH CHECK ADD CONSTRAINT [FK_UGroupDetail_Menus] FOREIGN KEY([RightID])
REFERENCES [dbo].[Menus] ([RightID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[UGroupDetail] CHECK CONSTRAINT [FK_UGroupDetail_Menus]
GO
ALTER TABLE [dbo].[UGroupDetail] WITH CHECK ADD CONSTRAINT [FK_UGroupDetail_UserGroup] FOREIGN KEY([GroupID])
REFERENCES [dbo].[UserGroup] ([GroupID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[UGroupDetail] CHECK CONSTRAINT [FK_UGroupDetail_UserGroup]
UGroupDetail have many groups as assigned to a new user but Menus table has only default groups which is 90 records
Menus table is a primary table and UGroupDetail is a Foreign key table
now i want to combined these tables and want to get only remaining records for each group
for example i have assigned 5 roles to GroupID 2 and now when i apply select commands the result should be 85 out 90 for GroupID 2
but i have not idea how to modify select query for get desired result

I don't really understand the tables. What is GroupID doing in the Menues table? And what does an entry without a RightName mean? Shouldn't that column be NOT NULL?
The UGroupDetail does not have any primary key. From your description, I would expect the PK to be (RightID, GroupID). But strangely enough, GroupID is nullable. So is RightName, but I think this column is redundant and should be removed.
Anyway, if I understand your question correctly, you need something like:
SELECT UG.Name, M.RightName
FROM   UserGroups UG
CROSS  JOIN Menus M
WHERE  NOT EXISTS (SELECT *
                   FROM   UGroupDetail UGD
                   WHERE  UG.GroupID = UGD.GroupID
                     AND  UG.RightID = M.RightID)
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • JDBC: How  to select only those records which contains col1 is NULL

    Hi All,
    In JDBC SELECT scenario.
    I wants to select only those records which contains col1 is NULL.
    I am trying as follows:
    <key>
    <col1 isNull="TRUE" />
    </key>
    but in moni/monitoring i am getting Following Error
    006-12-01 19:35:20 Error Unable to execute statement for table or stored procedure. 'BG_SALARY_SEND_SAP_D' (Structure 'SELECT') due to java.sql.SQLException: FATAL ERROR document format: structure 'SELECT', key element 'key' contains no values
    2006-12-01 19:35:20 Error Exception caught by adapter framework: Error processing request in sax parser: Error when executing statement for table/stored proc. 'BG_SALARY_SEND_SAP_D' (structure 'SELECT'): java.sql.SQLException: FATAL ERROR document format: structure 'SELECT', key element 'key' contains no values
    Please suggest how to do select rows with col1 is null.
    Regards

    Rohan,
    isNull= true is used to make the KEY element not mandatory.
    In your case, if the select query is
    select emp from emptest where empno is null
    , then the datatype will be,
    <root>
    <StatementName>
    <dbTableName action=”SELECT”>
      <table>emptest</table>
    <access>
    <emp></emp>
    </access>
    <key1>
    <b><empno hasQuot="NO">is null</empno></b>
    </key1>
    </dbTableName> 
    </StatementName>
    </root>
    I dont have a DB access to try this, but I think this should work.
    If this doesnt work, then you would need to use SQL_QUERY,
    <root>
    <StatementName>
    <anyName action=” SQL_QUERY”>
    <access>select emp from emptest where empno is null</access>
    </anyName > 
    </StatementName>
    </root>
    http://help.sap.com/saphelp_nw04/helpdata/en/2e/96fd3f2d14e869e10000000a155106/content.htm
    Regards,
    Bhavesh

  • How to select only one record at a time in ALV

    Hi all,
    I have to use ALV report.  Each record on the report output should have a button (or radio button) which will allow the record to be selected.  My requirement is to select only one record at a time.
    please guide me how to proceed further.
    regards
    manish

    hi
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/sampleCheckBoxProgram
    Regards
    Pavan

  • 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 entire logical processing consumes lot of time. Hence my RFC is taking huge time to produce result. (apprx 10 mins).
    Can i select these matching records in batch of 25 and display result for these 25 records??
    I'll give this batch size as input to RFC?
    Do anybody have any idea about how to tackle this situation and reduce response time?
    If u hav any better solution than this then pls pls let me know ASAP..
    Regards,
    Amey

    Amey Mogare  ,
                             Do One thing , create  a new importing parameter in your RFC , say current_trans_id. NOw on the first call pass the initial value for current_trans_id.
    then inside the logic .. change the select to
    select upto 25 rows where trnascation id > current_trans_id.
    next time when u call teh rfc.. send the last selected id as a value for current_trans_id.
    i think you can some how use this logic
    Regards
    Sarath

  • How to reterive just those records where street type is st

    IDX     ADDRESS_FORM
    1152     326 GREAT EASTERN HIGHWAY
    1158     CNR HAMILTON RD & CHARLOTTE ST
    1159 34 WESTERN ROAD
    SELECT IDX, ADDRESS_foRm FROM TEMP_AU_POI_INTERM WHERE instr(address_form,'ST') >0
    MY CONCERN IS THAT I WANT TO REPLACE ST TO STREET JUST IN 2ND RECORD NOT IN FIRST AND THIRD BECASUE THESE ARE PART OF THE NAME WHILE I JUST WANT TO CHANGE STREET TYPE. I WANT TO WRITE A QUERY WHICH SHOULD GIVE ME THE BELOW OUTPUT.
    1152     326 GREAT EASTERN HIGHWAY
    1158     CNR HAMILTON RD & CHARLOTTE STREET
    1159 34 WESTERN ROAD
    TO CHANGE ST TO STREET JUST IN 2ND RECORD
    THANKS

    or, the least fanciest of all, but clean and simple:
    SQL> with t as
      2  ( select 1152 idx,'326 GREAT EASTERN HIGHWAY' address from dual union all
      3    select 1158, 'CNR HAMILTON ST & CHARLOTTE ST' from dual union all
      4    select 1159, '34 WESTERN ROAD' from dual union all
      5    select 1196, 'CNR DALGETY RD & NTH STUART HIGHWAY' from dual
      6  )
      7  select idx
      8       , address old_address
      9       , trim(replace(' ' || address || ' ',' ST ',' STREET ')) new_address
    10    from t
    11  /
    IDX OLD_ADDRESS                                        NEW_ADDRESS
    #### 326 GREAT EASTERN HIGHWAY                          326 GREAT EASTERN HIGHWAY
    #### CNR HAMILTON ST & CHARLOTTE ST                     CNR HAMILTON STREET & CHARLOTTE STREET
    #### 34 WESTERN ROAD                                    34 WESTERN ROAD
    #### CNR DALGETY RD & NTH STUART HIGHWAY                CNR DALGETY RD & NTH STUART HIGHWAY
    4 rijen zijn geselecteerd.Regards,
    Rob.

  • Regarding Select query to select only 1000 records in Internal Table.

    Hello Friends,
    Please explain me to how to Select only 1000 records from data base table?
    For Example
    SELECT *  INTO TABLE ITAB                          OR            SELECT * INTO ITAB 
         FROM EKKO                                                                  FROM EKKO
    WHERE EBLEN IN S_EBLEN.                                            WHERE EBLEN IN S_EBLEN
    (Currently i am using)                                                       UP TO 1000 ROWS.
                                                                                    ENDSELECT.  (I do not want to use)
                                                                                    In this case Internal table may be store more then 1000 records. But i want to select first 1000 records.
    Please explain me.
    Regards
    Amit

    Hi,
    TABLES : ekko.
    selection-screen begin of block b1 with frame title text_t01.
    SELECT-OPTIONS: S_EBELN for ekko-EBELN.
    selection-screen end of block b1.
    DATA itab TYPE STANDARD TABLE OF ekko.
    SELECT *
      FROM ekko
      INTO TABLE itab
      UP TO 1000 ROWS
      WHERE EBELN IN S_EBELN.
    Thanks,
    Sri.

  • Selecting ONLY those fiels that need metadata written?

    How do I select ONLY those images that need the metadata written? I've got 40,000 images, change a number of keywords for different groups - add, delete, rename, whatever. I DON'T want to have to save metadata for all 40,00 files 'cause LR is already so slow... And doing a save metadata for every group I change is painful 'cause it takes foreve just to update even a few files. I've got the preference turned on to automatically write changes to xmp, but I'm not working with anything that has sidecar files...
    I want to be able to JUST select those images that need the metadata written out, then let it spend all night writing the changes.

    Thanks Lee... But, that doesn't appear to be what I'm seeing. I've got autowrite on (at least as far as I know I do), but I can watch a set of files where I've made changes to keywords and even after all activity has stopped there'll be files with the metadata indicator showing they haven't been synchronized with the disk.... AND, I can go to Bridge and open one of these files and see that the keywords haven't been updated on the disk......
    So, even though I have autowrite on, I can't be SURE the changes actually got written. And last night I selected everything and did a "Save metadata"... Just over 12 HOURS later it was at the 3% completed... This was on a catalog of approximately 35,000 images.
    This is why I'd like to be able to just select those images needing updating. Hopefully, it'd be faster.

  • I backed up my ipod during a windows backup.  how do i find those ipod files(not itunes) in the windows backup files? i've tried searching and i can't find

    i backed up my ipod during a windows backup.  how do i find those ipod files(not itunes) in the windows backup files? i've tried searching and i can't find

    so i plugged in my ipod and it asked if i wanted to backup the files before restoring it. 
    Do you mean iTunes asked if you wanted to backup files before restoring? If so the it is in the location I posted. You don't need to navigate to the backup. Once your restore your iPod it will ask if you want to restore from a backup and present you with the backups made before hand.
    To restore information from a backup, use one of the following methods after connecting your iOS device to the computer with which you normally sync:
    -Click the File menu and select Devices > Restore from Back up.
    Or
    -Open the iOS device's Summary tab. There are two ways to access this:
    -Click the device button in the upper right corner. (If viewing the iTunes Store, click the Library button in the upper right corner. The device button will then be visible.)
    -From any view in iTunes, click the View menu and select Show Sidebar. Select your iOS device in iTunes under Devices.
    -Click the Restore Backup button.

  • I want to delete a few contacts, apps, pics etc from my iphone, but when I delete and connect to my laptop they sync and come back again. How can I delete those items and not get them back when I connect my iphone to my laptop?

    I want to delete a few contacts, apps, pics etc from my iphone, but when I delete and connect to my laptop they sync and come back again. How can I delete those items and not get them back when I connect my iphone to my laptop?
    Also where exactly on the laptop is teh data stored.
    Thank you!!

    go to 'Edit' in the menu bar. Then choose 'Preferences'.
    you'll see a pop-up and there's a tab called 'Devices' there. If you click that, you will be able to check a box that says 'prevent automatic syncing for iPods, iPads and iPhones' or something like that.
    Hope this helps
    NB: if you don't even see the menu bar that has options like 'File, Edit, View, etc', first click the black/white square button on the top left of your screen, and then click 'show menu bar'. It should pop right up.
    Good luck

  • How to select the first record?

    Hi,
    Could anyone tell me how to select the first record of every
    group?
    ex, I want to find out every customer their first purcaseDate.
    CustomerID PurcaseDate Region
    A00000001 2001/01/01 AA
    A00000001 2001/02/02 AA
    A00000002 2001/03/01 AC
    A00000002 2001/05/07 AC
    A00000003 2001/03/05 DD
    result:
    A00000001 2001/01/01 AA
    A00000002 2001/03/01 AC
    A00000003 2001/03/05 DD
    Thanks

    Vincent,
    You could do it as Carl suggested, with a couple of
    corrections.  You would need to include the CustomNo column in
    the order by clause of your cursor.  You would also need to add
    a where clause to your update statement, otherwise everywhere
    Region in the table would be updated with the same value of the
    last CustomNo in the cursor, regardless of the CustomNo in the
    table.  See corrected code below:
    DECLARE
      CURSOR     cust
      IS
      SELECT     DISTINCT CustomNo, Region, Purchase_Date
      FROM       my_table
      ORDER BY   CustomNo, Purchase_Date, Region;
      c_customer VARCHAR2 (9) := '...';
      c_region   VARCHAR2 (2) := '..';
      cntr       NUMBER := 0;
    BEGIN
      FOR x IN cust
      LOOP
        IF x.CustomNo != c_customer
        THEN
          c_customer := x.CustomNo;
          c_region := x.Region;
        ELSE
          UPDATE my_table
          SET    Region = c_region
          WHERE  CustomNo = c_customer;
          cntr := cntr + 1;
          IF cntr = 25
          THEN
            COMMIT;
            cntr := 0;
          END IF;
        END IF;
      END LOOP;
      COMMIT;
    EXCEPTION
      WHEN OTHERS THEN 
        NULL;
    END;
    Another option is that you could just use one update statement,
    like this:
    UPDATE my_table a
    SET    Region =
           (SELECT DISTINCT Region
            FROM   my_table b
            WHERE  (CustomNo, Purchase_Date) IN
                   (SELECT   CustomNo, MIN (Purchase_Date)
                    FROM     my_table
                    GROUP BY CustomNo)
            AND    a.CustomNo = b.CustomNo)
    Barbara

  • How to restrict the last record and not moving to next reocrd

    1) how to restrict the last record and not moving to next reocrd.
    2) Also for the F6 key(for new record).

    When you are on the last record, next-record will create a new one, so that my question is do you want to forbid new record creation.
    Francois

  • Anyone know how to select only even or odd numbered files in lightroom?

    Anyone know how to select only even or odd numbered files in lightroom? I need to reduce the quantity of images in my timelapse sequence and this would help me greatly since there are 8250 images and doing this maually would be tediuos and make me want to kill myself.... : )

    Do this.
    If they are jpegs, use .jpg instead of CR2
    Be sure to save this as a preset, as you WILL need it again. Mine is named "select even CR2", that is why it says that in the upper right.

  • I am trying to create mobile pages using the steps file new new document page from sample mobile starters jquery mobile (cdn).  When "page from sample" is selected, the subsequent options are not available.  This seems like a silly question, but how do I

    I am trying to create mobile pages using the steps file>new>new document>page from sample>mobile starters>jquery mobile (cdn).  When "page from sample" is selected, the subsequent options are not available.  This seems like a silly question, but how do I acquire these options?

    You can get the latest jQuery Mobile Themes directly from jQuery Mobile's web site.
    https://demos.jquerymobile.com/1.1.0/docs/api/themes.html
    Or roll your own with ThemeRoller
    http://themeroller.jquerymobile.com/
    Nancy O.

  • ...notifications are a paid only feature, they are not available with a free account...

    Hi Support-Team,
    is there a chance to change this:
    "... notifications are a paid only feature, they are not available with a free account ..."
    If we can't send a notification to an other user FormsCentral doesn't make sence and will cancel the account... That would be a pity, because otherwise everything would work very well.
    Kind regards
    Andreas

    Hi;
    Thanks for your feedback, but notifications are a paid feature and are not available in a free account.  That isn't likely to change.  Hopefully there is enough value in this and the other features of a paid account for you to consider an upgrade.
    Thanks,
    Josh

  • How To select maximum Value in a specifieid field in internal table.

    How To select maximum Value in a specifieid field in internal table?

    Step : 1
    Sort itab by <Field1> descending.
    Just sort the internal table by the field.
    STEP: 2
    Then read the table at index 1.
    Read table itab index 1.               
    ITAB-FIELD = MAX .                  " Max field will come in the first row of the internal table.
    Regards,
    Gurpreet

Maybe you are looking for

  • Is "librariand" part of Lion ? if yes, what is it for ?

    I have this that's keep on coming back every 2 minutes in Console: 11-08-14 11:13:54.860 PM librariand: new client - cancelling idle timeout 11-08-14 11:13:54.860 PM librariand: no ubiquity account configured, not creating collection 11-08-14 11:13:5

  • ITunes 10.5 and Get Info facility - no longer working?

    Since I installed iTunes 10.5 last week, the Get Info facility for adding details of albums not on Gracenote doesn't work. The screen comes up as before but once you start typing iTunes crashes and quits. Anyone else got this problem?  Anyone solved

  • PowerPoint Crash after upgrading to Maverik

    Hi I was using Microsoft Office 2011 for Mac with Mountain Lion.It was working perfect. As soon as i upgraded to Maverick i can't play powerpoint slideshow. When i'm trying to play the slideshow the application crash. Process:         Microsoft Error

  • Can i upload only select songs to itunes match

    I currently carry 20 gigs of music around on my iphone and am looking to free up some space. If I use iTunes Match to upload my music to the cloud, will it take everything in my iTunes Library or just the songs/playlists/albums I select? This is crit

  • CITADEL DATABASE NOT CONFIGURED AS A RELATIONAL DATABASE

    HI: I have the same problem described by another member before, and I haven't found any  resolution of this problem: The problem was: >I enabled database logging, and configured the shared variables that I wanted to log. Then I deployed the variables