Jump to content

Recommended Posts

Posted

Hello guys
Konchem kindha unna Sql pyna help kaavali..meeku vasthey ikkada post cheyandi
Thanks


Suppose you have the two tables defined below (document, and document_line).



We'd like a query that will select all of the document ids which DO NOT have lines that are incomplete(document_line.incomplete = TRUE). Please note, the query should return ids for 'empty' documents (ie. no lines whatsoever in the document_line table). The query should return the list of ids with no duplicates.



We'd like as many variants as you can come up with. Please try to provide different solutions using the following SQL features: NOT EXISTS, NOT IN, LEFT JOIN, EXCEPT, GROUP BY, HAVING



Here is an example solution:

SELECT document.id FROM document WHERE (SELECT COUNT(*) FROM document_line WHERE document_line.document_id = document.id AND

incomplete) =0;





Here are the tables:

CREATE TABLE document(

id INTEGER NOT NULL PRIMARY KEY

);

CREATE TABLE document_line(

id INTEGER NOT NULL,

document_id INTEGER NOT NULL REFERENCES document(id),

line_number INTEGER NOT NULL,

incomplete BOOLEAN NOT NULL

);

Posted

Kotha ga join ayyava SQL lo...Its very easy ayina..evaru ee boothu rasindi...koncham alochinchu bro..vastadi.

 

 

SELECT document.id FROM document WHERE (SELECT COUNT(*) FROM document_line WHERE document_line.document_id = document.id AND

incomplete) =0;

×
×
  • Create New...