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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:18:21+00:00 2026-06-17T20:18:21+00:00

humbly I ask for help with the next problem. I have this one very

  • 0

humbly I ask for help with the next problem.

I have this one very simple. Don’t know how to describe it by words so I’ll do with an image.

table services

PERSONID     Service_id          chargeamount
1               3                 20.50
2               4                 80.50
3               5                 78.80

table charges

service_id     payed          extracharges
3               true              20.50
4               true              80.50
3               false             78.80

if there is any unpayed extracharge it must show true or false , and if the service id do not match in the second table it must be shown in the query with null values or other calculated value

Something like this

PERSONID     Service_id          chargeamount                        payed
1               3                 20.50                              false
2               4                 80.50                              true
3               5                 78.80                              null

but extra rows of the same row are not allowed like the ones created by joins.

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[SERVICES](
    [personid] [int] NULL,
    [service_id] [int] NULL,
    [chargeamount] [float] NULL
) ON [PRIMARY]

GO


insert into services (personid,service_id,chargeamount) values ( 1,3  ,20);
insert into services (personid,service_id,chargeamount) values ( 2,4  ,20);
insert into services (personid,service_id,chargeamount) values ( 3,5 ,20);



SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[charges](
    [payed] [bit] NULL,
    [service_id] [int] NULL,
    [extracharges] [float] NULL
) ON [PRIMARY]

GO

insert into services (service_id,payed,extracharges) values ( 3,true,20.50);
insert into services (service_id,payed,extracharges) values ( 3,false,78.80);
insert into services (service_id,payed,extracharges) values ( 4,false,80.50);
  • 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-17T20:18:22+00:00Added an answer on June 17, 2026 at 8:18 pm

    This is a simple left join on service_id. When there is at least one row with payed = false, false is shown. Otherwise true or null is shown, respectively.

    select s.*, case min(c.payed) when 1 then 'true' when 0 then 'false' else 'null' end
    from services s
    left join charges c on c.service_id = s.service_id
    group by s.personid, s.service_id, s.chargeamount
    

    SQLFiddle

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

Sidebar

Related Questions

I'd humbly appreciate any help on this one. I have a div with background:
Humbly asking for help with (of course) IE. I have a div that is
So I have an interview next week for a shop that makes heavy use
First, I ask that you not ask 'why.' In the famous words of Tennyson
My code does an error but I don't know how to correct it: public
I have a simple post AR class/table. Its based on the blog tutorial so
I have to humble myself and ask for some guidance on a topic I
I'm a humble programmer that hates SQL ... :) Please help me with this
I am reviewing this technology but have a few design concerns that made me
I'm a completely new to C++ and I'm having a very stupid problem. I

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.