Insert incoming data (and pk from 2nd table) into 1st table if true boolean value from 2nd table
Maybe the following SQL code will help you to find a solution.  The comments "-- step1, -- step 2" etc refer to your question. Dbfiddle here , also tested with MySQL 5.5.

create table device (
  serialno int primary key
, dataval int
, state tinyint
);
-- use tinyint instead of bool 0 = false, non-zero = true
-- https://dev.mysql.com/doc/refman/5.7/en/numeric-type-overview.html

insert into device (serialno, dataval, state)
values 
 (1,11,1),(2,22,0),(3,33,1),(4,44,0)
,(5,55,1),(6,66,0),(7,77,1),(8,88,0);

create table datain (
  id int auto_increment primary key
, device_serialno int references device(serialno)
, datain int
);


"Steps to complete" ... NOTICE: "step 3" contains both the SELECT and INSERT, as required (as one statement).  Steps 1 and 2 are just for "illustration".

-- step 1
select serialno, state from device;

-- find all devices and states (CASE - just to make the output more "readable")
select serialno
, state
, case 
    when state = 0 then 'disabled'
    else 'enabled'
  end state_
from device;

-- "supplied sensor serial number" 
set @id_ = 5;

-- step 2
select serialno, state 
from device
where serialno = @id_
  and state &lt;&gt; 0 ;

-- step 3
insert into datain (device_serialno, datain)
select serialno, dataval
from device
where serialno = @id_
  and state &lt;&gt; 0 ;


If you wanted to insert data from all enabled devices, you could maybe use something like ...

insert into datain (device_serialno, datain)
select serialno, dataval
from device
where state &lt;&gt; 0 ;