Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to do select distinct select in sql?
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/10842634/how-to-choose-which-row-to-insert-with-same-id-in-sql">how to choose which row to insert with same id in sql?</a> </p> </blockquote> <p>I have a table called "table_1" :</p> <pre><code>ID Index STATUS TIME DESCRIPTION 1 15 pending 1:00 Started Pending 1 16 pending 1:05 still in request 1 17 pending 1:10 still in request 1 18 complete 1:20 Transaction has been completed 2 19 pending 2:25 request has been started 2 20 pending 2:30 in progress 2 21 pending 2:35 in progess still 2 22 pending 2:40 still pending 2 23 complete 2:45 Transaction Compeleted </code></pre> <p>I need to insert these data into my second table "table_2" where only start and complete times are included, so my "table_2" should be like this:</p> <pre><code>ID Index STATUS TIME DESCRIPTION 1 15 pending 1:00 Started Pending 1 18 complete 1:20 Transaction has been completed 2 19 pending 2:25 request has been started 2 23 complete 2:45 Transaction Completed </code></pre> <p>Here is some code I already have, I have problem getting the right associated description because it does not appear in the <code>GROUP BY</code> clause.</p> <pre><code>INSERT INTO myTable2 (ID, STATUS, TIME) SELECT ID, STATUS, MIN(TIME) FROM myTable1 t1top WHERE EXISTS(SELECT * FROM myTable1 WHERE ID=t1top.ID AND STATUS='Complete') GROUP BY ID, STATUS ORDER BY ID ASC, STATUS DESC </code></pre> <p>If anyone can help me write sql query for this I would highly appreciate it.</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.
 

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