Android Question Query same table twice to Compare

sigster

Active Member
Licensed User
Longtime User
Hi


This is database I have and I need to Query same table twice to Compare
someone here who can help me with this

in the Picture Name-2 can be on left in the list or right in the list

Regards
sigster
 

Attachments

  • database.png
    database.png
    19.7 KB · Views: 122

sorex

Expert
Licensed User
Longtime User
select Name, Fiber, Tube from table where Name='Name-1'

&

select Name, Fiber, Tube from table where Name='Name-2'


but depending on what you actually want to do other queries (read 1 single query) might be more usefull.
 
Upvote 0

sigster

Active Member
Licensed User
Longtime User
Perhaps this picture explains this better I am compare two list
there is nothing I can link between , name, fiber, color are not the same



so have this is same table or one table for for each name
 

Attachments

  • colorcode.png
    colorcode.png
    6.7 KB · Views: 115
Upvote 0

sigster

Active Member
Licensed User
Longtime User
Name 1 and Name 2 and fiber dont have same number in the Attached Files colorcode the are the same but this is just sample
you can see it in Attached Files colorcode
 
Last edited:
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Name 1 and Name 2 and fiber dont have same number in the Attached Files colorcode the are the same but this is just sample
you can see it in Attached Files colorcode

:) I don't get it either. Can you explain more clearly what you are trying to achieve?

- Colin.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
I think that @sigster is referring to the fact that the first entry for name-1 list (the blue square) has code 1 in name1 while code 4 in Name2.
What a query should return from that..I don't know.
 
Upvote 0

sigster

Active Member
Licensed User
Longtime User
this is my Query but I dont get this like I show in just excel setup Attached Files: query

B4X:
SELECT c1.name,c1.fiber, c2.name,c2.fiber FROM code As c1 JOIN code As c2 ON c1.fiber = c2.fiber WHERE c1.name = 'Name-1' AND c2.name = 'Name-2'

this is the database sample
the zip file is rar file
 

Attachments

  • code.zip
    683 bytes · Views: 88
  • query.png
    query.png
    7.6 KB · Views: 102
Upvote 0

Mahares

Expert
Licensed User
Longtime User
this is my Query but I dont get this like I show in just excel setup Attached Files: query
You want your query to show all records in the code table where the name field can be either Name-1 or Name-2. Therefore, this is the query you need in SQLite:
B4X:
Dim strQuery As String = "SELECT name, fiber FROM code WHERE name IN('Name-1', 'Name-2')"
If we are still having trouble understanding your question, you may want to Google translate from French to English and post. Also, it is always better when you are posting data to show it as text instead of an image.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
like I show in just excel setup Attached Files: query
Based on the database you posted and the spreadsheet showing what data you want to display in post#10, I have attached a complete working example that displays the results that you like to achieve.
B4X:
Sub Activity_Create(FirstTime As Boolean)
    If Not(File.Exists(File.DirInternal, Starter.DBFileName))Then
        File.Copy(File.DirAssets, Starter.DBFileName, File.DirInternal,Starter.DBFileName)
    End If
    If FirstTime Then 
        Starter.SQL.Initialize(File.DirInternal,Starter.DBFileName,False)
    End If   
End Sub

Sub Activity_Resume
    DisplayData   
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then 
        Starter.SQL.Close
        Activity.Finish
    End If
End Sub

Sub DisplayData
    Dim strQuery As String = "SELECT name, fiber FROM code WHERE name IN('Name-1', 'Name-2')"
    Dim rs As ResultSet
    rs=Starter.SQL.ExecQuery(strQuery)
    Do While rs.NextRow
        Log($"${rs.GetString("name")} ${TAB}  ${rs.GetString("fiber")}"$)
    Loop
End Sub
Name-1 1
Name-1 2
Name-1 3
Name-1 4
Name-1 5
Name-1 6
Name-1 7
Name-1 8
Name-1 9
Name-1 10
Name-1 11
Name-1 12
Name-2 1
Name-2 2
Name-2 1
Name-2 2
Name-2 1
Name-2 2
 

Attachments

  • sigster121718.zip
    8.6 KB · Views: 93
Upvote 0
Top