question

FatPap avatar image
FatPap asked

Join 3 tables in SQLite

Hello, I want to join these 3 tables from my database: table checklog: MacAdress timestamp result user 4C626D3BB6D4 1394 1 frank 4C626D3BB6D4 1395 0 dave table service: MacAdress timestamp text 5C626D3BB6D5 1396 test table error: MacAdress timestamp error1 error2 errortext 4C626D3BB6D4 1397 0 0 OK Result should be: MacAdress timestamp result user text error1 error2 errortext 4C626D3BB6D4 1394 1 frank 4C626D3BB6D4 1395 0 dave 5C626D3BB6D5 1396 test 4C626D3BB6D4 1397 0 0 OK What SQLite command should i use to get the above result? The database structure is as follows: CREATE TABLE [checklog] ( [MacAdress] TEXT NOT NULL , [timestamp] INTEGER NOT NULL , [result] INTEGER , [user] TEXT , CONSTRAINT [sqlite_autoindex_checklog_1] PRIMARY KEY ( [MacAdress], [timestamp] ) ); CREATE TABLE [error] ( [MacAdress] TEXT NOT NULL , [timestamp] INTEGER NOT NULL , [error1] INTEGER , [error2] INTEGER , [errortext] TEXT , CONSTRAINT [sqlite_autoindex_error_1] PRIMARY KEY ( [MacAdress], [timestamp] ) ); CREATE TABLE [service] ( [MacAdress] TEXT NOT NULL , [timestamp] INTEGER NOT NULL , [text] TEXT , CONSTRAINT [sqlite_autoindex_service_1] PRIMARY KEY ( [MacAdress], [timestamp] ) );
tablessqlite
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
FatPap avatar image
FatPap answered
Already found an answer to my question that works for me: select Macadress, timestamp, result, user, '', '', '', '' from checklog union select MacAdress, timestamp, '', '', '', error1, error2, errortext from error union select MacAdress, timestamp, '', '', text, '', '', '' from service order by timestamp
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.