Get Record parent table based on child table. Plz help

  • CREATE TABLE [dbo].[Managements](

    [ManagementId] [int] NOT NULL,

    [FTAManagementNo] [varchar](35) NULL

    )

    CREATE TABLE [dbo].[MgmtCountries](

    [MgmtCountryId] [int] not null,

    [CountryId] [int] null,

    [ManagementId] [int] null ,

    [FTAManagementNo] [varchar](35) NULL

    )

    i want to get only those ManangementId which is available in MgmtCountries table with countryid=19

    Conditions: 1. Get MangementId only if countryid matched

    2. If record exist in MgmtCountries table with another countryid then dont return MangementId

    3. If Record does not exist in MgmtCountries table at all the return MangementId

  • shkoli (10/27/2015)


    CREATE TABLE [dbo].[Managements](

    [ManagementId] [int] NOT NULL,

    [FTAManagementNo] [varchar](35) NULL

    )

    CREATE TABLE [dbo].[MgmtCountries](

    [MgmtCountryId] [int] not null,

    [CountryId] [int] null,

    [ManagementId] [int] null ,

    [FTAManagementNo] [varchar](35) NULL

    )

    i want to get only those ManangementId which is available in MgmtCountries table with countryid=19

    Conditions: 1. Get MangementId only if countryid matched

    2. If record exist in MgmtCountries table with another countryid then dont return MangementId

    3. If Record does not exist in MgmtCountries table at all the return MangementId

    Select ManagementId

    from dbo.Managements m

    where not exists (select 1 from dbo.MgmtCountries mc where mc.CountryId <> 19 and mc.ManagementId = m.ManagementId)


Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply