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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:59:07+00:00 2026-06-15T10:59:07+00:00

Edit: Sorry to not mention before this is on a postgres 8.3 implementation. I

  • 0

Edit: Sorry to not mention before this is on a postgres 8.3 implementation.

I have a table of four columns that was built today table.

Source_IP, Destination_IP, user_type, ut_bool

The user_type column continually gets new entries and so I want to compare it to a table o historical entries to see if it is new or not for the day in question. The source_ip, destination_Ip can be considered the primary key

10.1.1.2, 30.30.30.1, type1, 0
10.1.1.2, 30.30.30.1, type4, 1
10.1.1.2, 30.30.30.4, type5, 0
10.1.1.2, 30.30.30.4, type3, 0
10.1.1.2, 30.30.50.9, type2, 0
10.1.1.4, 30.30.30.4, type4, 0
10.1.1.4, 30.30.30.4, type3, 1

I am having trouble returning a 1 to a column for a given group of (source_ip, destination_ip) pairs if a least one source_ip,destination_ip, user_type pair has a 1 next to it so for example I want to get

10.1.1.2, 30.30.30.1, 1
10.1.1.2, 30.30.30.4, 0
10.1.1.4, 30.30.30.4, 1

I am not sure how to use the exists statement correctly.

How do I fix the following query?

select source_ip, destination_ip,
(
select
case when exists 
(select true from table
where ut_bool =1)
then '1'
else '0' end
) as ut_new
from
table;

My query keeps returning because I am not using the exists statement correctly:

10.1.1.2, 30.30.30.1, 0
10.1.1.2, 30.30.30.4, 0
10.1.1.4, 30.30.30.4, 0
  • 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-15T10:59:08+00:00Added an answer on June 15, 2026 at 10:59 am

    I’d suggest modification of your SQL statement:

    SELECT SOURCE_IP,
      DESTINATION_IP,
      CASE SUM(UT_BOOL)
        WHEN 0
        THEN 0
        ELSE 1
      END AS UT_NEW
    FROM test_table_name
    GROUP BY SOURCE_IP,
      DESTINATION_IP;
    

    Executed on your test data returns:

    10.1.1.2    30.30.50.9  0
    10.1.1.2    30.30.30.1  1
    10.1.1.2    30.30.30.4  0
    10.1.1.4    30.30.30.4  1
    

    Tested and working on Oracle and Postgres

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

Sidebar

Related Questions

EDIT: Sorry my question was not clear, why do books/articles prefer implementation#1 over implementation#2?
Edit: I'm sorry, but I forgot to mention that I'll need the values of
EDIT: Sorry I forgot to mention, I'm not using the implemented sha512 crypt because
EDIT Sorry I forgot the most important part here. Each key can have more
[edit]: I'm terribly sorry for my timing on asking this question. I've just discovered
EDIT: It does work (sorry). Something in this script is causing it to stop
Sorry if this question will sound too chaotic, feel free to edit it. I
Sorry, this is my first time using this forum. Apparently people can edit my
IMPORTANT EDIT: Sorry everyone, i made a big mistake in the structure. char *name;
Sorry for bumpy topic name (feel free to edit if you find more fitting

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.