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 8983639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:53:24+00:00 2026-06-15T20:53:24+00:00

Table1 CatId Name 1 Category1 2 Category2 3 Category3 Table2 FieldId FieldName FieldValue Category

  • 0
Table1

    CatId     Name
    1       Category1
    2       Category2
    3       Category3

Table2

FieldId     FieldName    FieldValue   Category
1            Field1        Value1        1
2            Field2        NULL          1
3            Field3        NULL          2
4            Field4        NULL          2
5            Field5        Value2        3
6            Field6        Value3        3

I have a table structure as shown above. I want to fetch fields under category when any of the Fieldvalue is not null under that category. For my above example result should be:

FieldId     FieldName    FieldValue   Category
    1         Field1        Value1        1
    2         Field2        NULL          1
    5         Field5        Value2        3
    6         Field6        Value3        3

As you can see under category1 field2 has null value but it is still displayed. Under category 2 both field3 and field4 has null values and so it should not be selected.

Can someone help me with sql query for the above problem? One way i thought is to use groupby category and see for the count(FieldValue)>0 where fieldvalue is not null. but i am stuck how to bring this logic into sql?

Thanks in advance.

  • 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-06-15T20:53:25+00:00Added an answer on June 15, 2026 at 8:53 pm
    SELECT
        FieldId 
      , FieldName 
      , FieldValue 
      , Category
    FROM 
        Table2 AS t
    WHERE
        EXISTS
            ( SELECT *
              FROM Table2 AS tn
              WHERE tn.Category = t.Category
                AND tn.FieldValue IS NOT NULL
            ) ;
    

    or:

    SELECT
        t.FieldId 
      , t.FieldName 
      , t.FieldValue 
      , t.Category
    FROM 
            Table2 AS t
        JOIN
            ( SELECT Category
              FROM Table2
              GROUP BY Category
              HAVING MIN(FieldValue) IS NOT NULL
            ) AS tn 
          ON tn.Category = t.Category ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Table1: id - name 1 - john 2 - david 3 - dilio Table2:
Table1 ID Loc ----------- 001 null 002 null 003 PYD 004 null .... Table2
table1 is the parent table with a column ID and table2 has a column
Table1: ResourceID Name0 (STRING) NumberOfLongons0 (INT) LastLogon0 (DateTIME) Table2: ResourceID NetbiosName0 I am trying
Say I have 3 tables. Table1 contains client_id and client_name. Table2 contains client_id, client_catid_1,
I want to create Many-One Mapping between two tabels, Expense(ID, NAME, CATEGORY) and Category(ID,
My tables: Table cat has id, name Table user has id, uname, catid Sample
I have this category table Category ============ id name ref_id 1 cat1 0 2
I have a table like this- id name ordering catid 1 parent1 1 0
i have two table: category id | name products id | cat_id | name..

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.