Title
#general
t

TonyC

08/23/2018, 6:55 PM
Does anyone know how to do a conditional query on 1 table if data exists in another? I created 2 tables, location and speedtest. if you run a query against speedtest it will run the test so I don't want to query against it unless certain conditions are met. IE if (select location = 'somewhere') Then (select * from speedtest). The location and speedtest tables do not share any common attributes, and there will be a lot of other conditions added in the future so I don't want to have to modify the speedtest table to include additional common attributes down the road. I can make it work using a case statement, but it will only work for 1 attribute in the speedtest table. I need to be able to pull all values. Example: SELECT location, CASE location WHEN 'Building R (Wireless)' THEN (SELECT download FROM speedtest) ELSE 'skipped' END download FROM location Will return hostname | download | location <host> | 601.34Mbit/s | Building R (Wireless) But I need all the attributes out of speedtest, which include latency, upload, etc. Using the case statement I would have to create an additional case for every other attribute which would mean the speedtest would run multiple times. Any ideas?
f

fritz

10/23/2018, 2:16 PM
@TonyC Did you ever solve this problem? If not you can do it with an EXISTS condition
2:19 PM
So essentially you run your
select latency, upload, etc from speedtest WHERE EXISTS (select location from locations where location = 'Building R (Wireless)');
t

TonyC

10/23/2018, 3:43 PM
Actually I found it was not necessary. Using the WHERE clause appears to execute in order, so if the Location was not in Building R (Wireless) the test would not run. I thought I had tested that, but apparently I didn't do it correctly 🙂 Thanx for your suggestion though
f

fritz

10/23/2018, 3:45 PM
no problem! Glad to hear you solved it in the end 🙂