I'm not trying to answer your question here, but want to tell you what database structure would be appropriate for the task described.
- You have a book table with a book id. Each record contains one book.
- You have a word table with a word id. Each record contains one word.
- Now you want to have a list of all existing book-word combinations.
The table you would create for this relation is called a bridge table. One book can contain many words; one word can be contained in many books; a n:m relation. The table has two columns: the book id and the word id. The two combined are the table's primary key (a composite key). Each record contains one existing combination of book and word.
Here are some examples how to use this table:
To find all words contained in a book:
select word
from words
where word_id in
(
select word_id
from book_word
where book_id =
(
select book_id
from books
where name = 'Peter Pan'
)
);
(That's just an example; the same can be got with joins instead of subqueries.)
To select words that occur in two particular books:
select word
from words
where word_id in
(
select word_id
from book_word
where book_id in
(
select book_id
from books
where name in ('Peter Pan', 'Treasure Island')
)
group by word_id
having count(*) = 2
);
To find words that occur in only one book:
select w.word, min(b.name) as book_name
from words w
join book_word bw on bw.word_id = w.word_id
join books b on b.book_id = bw.book_id
group by w.word_id
having count(*) = 1;
select * from mytable where col1 = 'row3'suffice? If not; why not? What does your table actually contain? It looks queer for an entity to only have boolean attributes.