Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
Id File-Name Descrption
1  yyyy      Started
2  yyyy      incompleted
3  rrrr      Started
4  tttt      started
5  uuuu      started
6  rrrr      completed
7  tttt      completed
8  uuuu      incompleted

A table having three rows where I need to write a query/condition to get all the completed records in that table.

Result should be


Select * from Table_name where file-name = start and file-name = complete;   ---It's not working...
share|improve this question

closed as off topic by Jack Douglas Dec 17 '12 at 19:24

Questions on Database Administrators Stack Exchange are expected to relate to database administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Have you heard of SQL Fiddle? As we are struggling to understand you, perhaps you could put together a working example there and paste it into the question (or link to it)? – Jack Douglas Dec 17 '12 at 19:11
Until then, I'm closing the question and from what I can understand, it's off topic here (because it is basic not advanced SQL, see the faq). – Jack Douglas Dec 17 '12 at 19:24

You say the table has 3 rows but then you post 8 rows of data.

If I go by the text of your question, it sounds like you just want

  FROM table_name
 WHERE description = 'completed'

If I try to guess what you really want based on the SQL statement that you posted, my guess is that you want all the file names where there exists a row with a status of 'started' and a status of 'completed' (I am guessing that the 'Started' description from id values 1 and 3 are erroneously capitalized) then you would want

SELECT id, file_name
  FROM table_name
 WHERE description in ('started', 'completed')
 GROUP BY id, file_name
HAVING COUNT(distinct description) = 2
share|improve this answer
Thank for the answer and sorry for the mistake If i got Completed or completion or Stop or end as the ending of the record in matching with start record how can do it ....And its not taking "," between started and completed – user16301 Dec 17 '12 at 18:54
@user16301 - Define "its not taking". Are you getting an error? If so, what error? Are you sure that you are specifying two string literals in the IN statement (as I am doing here) rather than using an unquoted identifier as you did in the query you posted initially? – Justin Cave Dec 17 '12 at 19:01

As you have only data like 'rrrr' and 'tttt' in file-name, checking for file-name = 'started' will never return any rows. Instead, you need something like:

SELECT t1.file_name
    table_name t1
    JOIN table_name t2 ON t1.file_name = t2.file_name
    t1.description = 'started'
    AND t2.description = 'completed'

But before jumping into copying queries from here, you should in first place get familiar with SQL syntax and technical terms like row, column, join, string literal and so on.

share|improve this answer
Thank for the answer If i got Completed or completion or Stop or end as the ending of the record in matching with start record how can do it ........Its in one table only – user16301 Dec 17 '12 at 18:56
Instead of = 'completed' use IN ('completed', 'completion', 'end', 'stop'). Use capitals as your values require it ('Stop' and 'stop' are not equal). – dezso Dec 17 '12 at 18:59
Its not taking "," showing error and if i use and its not excuting – user16301 Dec 17 '12 at 19:00
@user16301 I bet you don't use apostrophes. They are there for a reason... – dezso Dec 17 '12 at 19:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.