Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7693827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:10:47+00:00 2026-05-31T21:10:47+00:00

I having trouble in my sql query .Please see my example As u see,

  • 0

I having trouble in my sql query .Please see my
example

enter image description here

As u see, the inventory Report is the parent for the stock alert and stock movement report.

Now i got a question. How can i select the parent’s read access to become ‘Y’ when there has any child record which has ‘Y’ read_access? On the other hand , if there aren’t any existing child record which has ‘Y’, the parent read_acess will become ‘N’

Sorry for my bad english. Please help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:10:48+00:00Added an answer on May 31, 2026 at 9:10 pm

    This should work:

    SELECT ISNULL(CHILDREN_TABLE.READ_ACCESS, PARENT_TABLE.READ_ACCESS) AS READ_ACCESS
    FROM TABLE AS PARENT_TABLE
        LEFT JOIN TABLE AS CHILDREN_TABLE
            ON CHILDREN_TABLE.Parent = PARENT_TABLE.Child
    

    It will give you duplicates, though (2 rows for Inventory Report, one for Stock Alert Report and one for Stock Movement Report) You can resolve this with a SELECT DISTINCT …

    OR, I believe adding a GROUP BY in the children table will solve the duplicate:

    SELECT ISNULL(CHILDREN_TABLE.READ_ACCESS, PARENT_TABLE.READ_ACCESS) AS READ_ACCESS
    FROM TABLE AS PARENT_TABLE
        LEFT JOIN (SELECT Parent, READ_ACCESS FROM TABLE GROUP BY Parent) AS CHILDREN_TABLE
            ON CHILDREN_TABLE.Parent = PARENT_TABLE.Child
    

    Now, you will still get a duplicate if there is a child that has READ_ACCESS of Y and another that has READ_ACCESS of N. However, this sounds like something that would need to be discussed with your business rules anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble with a LINQ to SQL query getting the min value using
I'm having trouble with a query in SQL Server 2008 on some forex trading
I'm having trouble trying to optimize the following query for sql server 2005. Does
I am having trouble with a SQL query. SELECT t.topicname, m. *, ms.avatar FROM
I am having trouble running a simple sql query in Microsoft SQL Server 2005
I'm having trouble trying to define the SQL query for this table: There's a
I'm having trouble creating a query. I need to create a SQL query where
I'm having trouble getting my head around converting a traditional SQL aggregate query into
I'm having trouble with an SQL query in a scope. I need to return
I'm having trouble with a SQL query, I can't think how to phrase it.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.