SQLite Forum

How can I merge results from two SELECTs?
Login
Hello, 

Assuming I have the following table:

	CREATE TABLE SnapshotParameters(
		snapshot_id   integer,
		param_id      integer,
		param_value   integer
	);

In this table I hold the following data:

	-- Original snapshot (values are 1)
	INSERT INTO SnapshotParameters (snapshot_id, param_id, param_value) VALUES ( 1, 1, 1);
	INSERT INTO SnapshotParameters (snapshot_id, param_id, param_value) VALUES ( 1, 2, 1);
	INSERT INTO SnapshotParameters (snapshot_id, param_id, param_value) VALUES ( 1, 3, 1);
	INSERT INTO SnapshotParameters (snapshot_id, param_id, param_value) VALUES ( 1, 4, 1);
	INSERT INTO SnapshotParameters (snapshot_id, param_id, param_value) VALUES ( 1, 5, 1);
	-- Edited snapshot (values are 2)
	INSERT INTO SnapshotParameters (snapshot_id, param_id, param_value) VALUES ( 2, 3, 2);
	INSERT INTO SnapshotParameters (snapshot_id, param_id, param_value) VALUES ( 2, 4, 2);

Now I want to run a query that will return to me <b>one result per parameter-id</b> with the following logic: <br>
If parameters exists in snapshot-2 then return this value,<br>
Otherwise - return value from snapshot-1.

Result example:

	1, 1, 1
	1, 2, 1
	2, 3, 2
	2, 4, 2
	1, 5, 1

Thanks for any tip,<br>
PazO