SELECT name as "Device Name",description as "Description",last_seen_at as "Last Seen At",collector as "Collector",alias_name as "Alias Name",
model as "Model",device_types as "Device Types",ip_function_type as "IP Function Type",system_oid as "System OID",vendor as "Vendor",
host_name as "Host Name",primary_ip_address as "Primary IP Address",city as "City",state as "State",
collection_system as "Collection System",location as "Location",location_description as "Location Description",
std_device_name as "Standard Device Name",collector_alternate_id as "Collector Alternate Id",create_time as "Create Time",
device_model_id as "Device Model Id",location_id as "Location Id",display_name as "Display Name",
display_description as "Display Description",supported_protocols as "Supported Protocols",polled_item_count as "Polled Iten Count",
life_cycle_state as "Life Cycle State",life_cycle_state_last_chg_on as "Life Cycle State Last Change On",
contact_status as "Contact Status",calculated_contact_status as "Calculated Contact Status",last_updated_at as "Last Updated At",npm_status as "NPM Status",node_id as "Node Id"
FROM NPM_DEVICES
WHERE --device_id > 20000000 and
(Lower(name) LIKE Lower('%$Search%') or Lower(description) LIKE Lower('%$Search%') or Lower(collector) LIKE Lower('%$Search%')
or Lower(alias_name) LIKE Lower('%$Search%') or Lower(model) LIKE Lower('%$Search%') or Lower(device_types) LIKE Lower('%$Search%')
or ip_function_type LIKE '%$Search%' or Lower(display_name) LIKE Lower('%$Search%') or
Lower(display_description) LIKE Lower('%$Search%') or Lower(system_oid) LIKE Lower('%$Search%') or
Lower(location) LIKE Lower('%$Search%') or Lower(location_description) LIKE Lower('%$Search%') or
Lower(vendor) LIKE Lower('%$Search%') or Lower(life_cycle_state) LIKE Lower('%$Search%') or
Lower(contact_status) LIKE Lower('%$Search%') or Lower(state) LIKE Lower('%$Search%') or
Lower(city) LIKE Lower('%$Search%') or Lower(std_device_name) LIKE Lower('%$Search%') or
collector_alternate_id LIKE '%$Search%' or primary_ip_address LIKE '%$Search%'
or Lower(host_name) LIKE Lower('%$Search%'))
LIMIT $resultlimit;
Above query need to get devices which have been last seen within the last 30 days