Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to check if a column data from table exist in the same table?
    primarykey
    data
    text
    <p>How can I do this in SQL select statement..</p> <p>Considering I have this table</p> <pre><code>ID_A - DATE1 - DATE2 ===================== CD99 - 11/25 - 12/08 AB23 - 11/20 - 11/22 AB23 - 11/22 - 12/01 XP72 - 11/23 - 12/08 </code></pre> <p>You will notice that ID_A=AB23 has two entries and <strong>DATE2 of first line is equal to DATE1 of the second line</strong>, this means that these two lines are connected.</p> <p><strong>So, how can I get or create my select statement to view these lines that are connected to each other?</strong></p> <p>EDIT: What I was trying to do in my select statement is this: a. check DATE2 if is not null b. from there, check DATE2 if it exists in the DATE1 of whole table and return the value of columns.</p> <p>What I would like to get should look like this:</p> <pre><code>ID_A - DATE1 - DATE2 ===================== AB23 - 11/20 - 11/22 AB23 - 11/22 - 12/01 </code></pre> <p>P.S. I was hoping to not do this using a loop.. As this tend to get the server too slow to respond when I get to have too much of data. - Let me note that i am comparing columns within the same database..</p> <p>@fthiella here is my sample data with the scenario im referring to..</p> <pre><code>ID_A - DATE1 - DATE2 ===================== CD99 - 11/25 - 12/08 AB23 - 11/20 - 11/22 AB23 - 11/22 - 12/01 XP72 - 11/23 - 12/08 PQ10 - 11/20 - -n/a- LM88 - 11/21 - -n/a- PQ10 - 11/15 - 11/20 </code></pre> <p>from there i would like to get these:</p> <pre><code>ID_A - DATE1 - DATE2 ===================== CD99 - 11/25 - 12/08 AB23 - 11/22 - 12/01 XP72 - 11/23 - 12/08 </code></pre> <p>here's a quick explanation of why i excluded the others:</p> <pre><code>ID_A - DATE1 - DATE2 ===================== CD99 - 11/25 - 12/08 - not excluded AB23 - 11/20 - 11/22 - excluded because DATE2 is connected to DATE1 of same ID_A AB23 - 11/22 - 12/01 - not excluded XP72 - 11/23 - 12/08 - not excluded PQ10 - 11/20 - -n/a- - excluded because DATE2 is null LM88 - 11/21 - -n/a- - excluded because DATE2 is null PQ10 - 11/15 - 11/20 - excluded because DATE2 is connected to DATE1 of same ID_A (regardless if DATE2 of that line is null) </code></pre> <p>priority of condition can be - exclude null DATE2 first, then check comparison and exclude those lines that are preceeding other lines..</p> <p>Sorry for having so much of your time, I really appreciate every help you have given me.. for now this question can be tagged as ANSWERED, thanks again fthiella..</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.
 

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