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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:33:17+00:00 2026-06-06T17:33:17+00:00

What I am trying to do, using java, is: access a database read a

  • 0

What I am trying to do, using java, is:

  • access a database
  • read a record from table “Target_stats”
  • if the field “threat_level” = 0, doAction1
  • if the field “threat_level” > 0, get additional fields from another table “Attacker_stats” and doAction2
  • read the next record

Now I have everything I need but a well thought out SQL statement that will allow me to only go through the database only once, if this does not work I suspect I will need to use two separate SQL statements and go through the database a second time. I do not have a clear understanding of case statements, so I will just provide pseudo code using an if statement.

SELECT A.1, A.2, A.3
   if(A.3 > 0){
      SELECT A.1, A.2, A.3, B.1, B.3 
      FROM A 
      JOIN B 
      ON A.1 = B.1
      }
FROM A

Can anyone shed any light on my situation?

EDIT: Thankyou both for your time and effort. I understand both of your comments and I believe that I am headed more towards the right direction however, I’m still having some trouble. I didn’t know about SQLfiddle before so I have now gone ahead and made a sample DB and tried to demonstrate my purpose. Here is the link: http://sqlfiddle.com/#!3/ea108/1 What I want to do here is Select target_stats.server_id, target_stats.target, target_stats.threat_level Where interval_id=3 and if the threat_level>0 I want to retrieve attack_stats.attacker, attack_stats.sig_name Where interval_id=3. Again, thankyou for your time and effort it is very useful to me

EDIT: after some tinkering around, I figured it out. thankyou so much for your 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-06-06T17:33:19+00:00Added an answer on June 6, 2026 at 5:33 pm

    As @Ocelot20 said, SQL is not procedural code. It is based on set-based operations, not per row operations. One immediate consequence of this is that the SELECT in your pseudo-example is wrong as it relies on rows in the same result set having different column lists.

    That said, you can get pretty close to your pseudo-code example, if you can tolerate NULL values where the join is not possible.

    Here’s an example that (to me anyway) seems to be close to what your are driving at:

    select *
    from A 
      left outer join B 
        on A.a = B.d and A.a > 2
    

    You can see it in action in this SQLFiddle, which should show you what sort of output to expect.

    Note that what this is actually saying is something like this:

    Fetch all the records from table A and also fetch any records from
    table B have their d column the same as the a column in table
    A, provided the value of A.a is greater than 2.

    (This was picked for convenience. In my rather contrived example shifting the conditional column does not effect the output as can be see here).

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

Sidebar

Related Questions

i am trying to establish a connection with access database using java... But while
I am trying to read file headers using java, I want to get file
i am trying to do access the database table records using swing event handling
I trying to implement the active record pattern using Java/JDBC and MySQL along with
I am trying to access an exchange server to read emails from a specific
I'm using MATLAB to access a postgresql database. I'm running into problems trying to
I am currently trying to map my Java class hierarchy into my database using
I'm trying to make a program using java to access this website by inserting
I can access the database either from a .NET program (using ODBC) or through
I am trying to insert values into Ms access database .The table has 4

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.