I wish to get SINGLE DISTINCT values from a Combination of 2 Database Columns .
The Columns (Tag1 & Tag2) contain string values(Tags). There is duplicated tags within each colum and duplicated tags between / in both columns.
The query results are added to a Single Tag List which is to contain only One Single Occurrence of each individual tag value.
This First attempt resulted in duplicate Tags... (I kind of understand why this is failing.. Distinct in Tag2 , so Tag1 (duplicate) is also added... maybe)
After more research , this was the suggested method / query ...
But this only results in an Error ... Caused by: java.sql.SQLException: no such column: 'Tag2'
Without question there is a column "Tag2" . It contains Tag values and I can log its contents with the First query method above.
Is the 2nd Query Correct , if so why the "no such column error" ?
Am I querying the returned result set correctly ?
But, at the end of the day , if there is a better way of storing 1 or 2 "Tags" for each DB record , and being able to populate a list with Single Unique Tags I am all ears.
Thanks & Regards
The Columns (Tag1 & Tag2) contain string values(Tags). There is duplicated tags within each colum and duplicated tags between / in both columns.
The query results are added to a Single Tag List which is to contain only One Single Occurrence of each individual tag value.
This First attempt resulted in duplicate Tags... (I kind of understand why this is failing.. Distinct in Tag2 , so Tag1 (duplicate) is also added... maybe)
B4X:
Dim rs As ResultSet
rs = oSQL.ExecQuery2("SELECT DISTINCT Tag1,Tag2 FROM tblHistory WHERE Person = ?", Array As String(profile))
Do While rs.NextRow
If rs.GetString("Tag1") <> "" Then lstTags.Add(rs.GetString("Tag1"))
If rs.GetString("Tag2") <> "" Then lstTags.Add(rs.GetString("Tag2"))
Loop
After more research , this was the suggested method / query ...
B4X:
Dim rs As ResultSet
rs = oSQL.ExecQuery2("SELECT DISTINCT Tag1 From tblHistory UNION SELECT DISTINCT Tag2 FROM tblHistory WHERE Person = ?", Array As String(profile))
Do While rs.NextRow
If rs.GetString("Tag1") <> "" Then lstTags.Add(rs.GetString("Tag1"))
If rs.GetString("Tag2") <> "" Then lstTags.Add(rs.GetString("Tag2"))
Loop
But this only results in an Error ... Caused by: java.sql.SQLException: no such column: 'Tag2'
Without question there is a column "Tag2" . It contains Tag values and I can log its contents with the First query method above.
Is the 2nd Query Correct , if so why the "no such column error" ?
Am I querying the returned result set correctly ?
But, at the end of the day , if there is a better way of storing 1 or 2 "Tags" for each DB record , and being able to populate a list with Single Unique Tags I am all ears.
Thanks & Regards
Last edited: