Note that there are some explanatory texts on larger screens.

plurals
  1. POCan a SQL Case statment be used to test if a Join statement should be used?
    primarykey
    data
    text
    <p>What I am trying to do, using java, is:</p> <ul> <li>access a database</li> <li>read a record from table "Target_stats"</li> <li>if the field "threat_level" = 0, doAction1</li> <li>if the field "threat_level" > 0, get additional fields from another table "Attacker_stats" and doAction2</li> <li>read the next record</li> </ul> <p>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.</p> <pre><code>SELECT A.1, A.2, A.3 if(A.3 &gt; 0){ SELECT A.1, A.2, A.3, B.1, B.3 FROM A JOIN B ON A.1 = B.1 } FROM A </code></pre> <p>Can anyone shed any light on my situation? </p> <p>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: <a href="http://sqlfiddle.com/#!3/ea108/1" rel="nofollow">http://sqlfiddle.com/#!3/ea108/1</a> 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</p> <p>EDIT: after some tinkering around, I figured it out. thankyou so much for your help</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload