I got a table called tblWord in a SQLite database like this.
|IdWord | Word | One | Two | Three | Four |
|-----------------------------------------------------|
| 1 | Alex | I Alex | You Alex | He Alex |She Alex|
Of course this sample is a concept, trying to simplify the question.
I'm trying to search for Alex in database in a way I get a separate result record for each field. The result should be like this
|IdWord | Word | One | Two | Three | Four |
|-----------------------------------------------------|
| 1 | Alex | I Alex | null | null | null |
| 1 | Alex | null | You Alex | null | null |
| 1 | Alex | null | null | He Alex | null |
| 1 | Alex | null | null | null |She Alex|
I tried this query as it somehow has worked before in the almost same situations.
SELECT mw.IdWord, mw.IdType, mw.Word, qw.One, iw.Two, sw.Three, pw.Four
FROM tblWord AS mw LEFT OUTER JOIN
tblWord AS qw ON mw.IdWord = qw.IdWord LEFT OUTER JOIN
tblWord AS iw ON mw.IdWord = iw.IdWord LEFT OUTER JOIN
tblWord AS sw ON mw.IdWord = sw.IdWord LEFT OUTER JOIN
tblWord AS pw ON mw.IdWord = pw.IdWord
WHERE (qw.One LIKE '%Alex%') OR
(iw.Two LIKE '%Alex%') OR
(sw.Three LIKE '%Alex%') OR
(pw.Four LIKE '%Alex%')
But in this case, it just shows the results like this:
|IdWord | Word | One | Two | Three | Four |
|-----------------------------------------------------|
| 1 | Alex | I Alex | You Alex | He Alex |She Alex|
Is there anyway to get the result, the way I'm looking for?
Aucun commentaire:
Enregistrer un commentaire