2017-08-08 3 views
0

Es gibt zwei Tabellen, mit denen ich arbeite (ft_form_1 & ft_field_options).Wählen Sie Zeilen aus, die an einem bestimmten Datum in keiner anderen Tabelle vorhanden sind

ft_form_1

 submission_id facility_id admits reporting_date timestamp 
     1    111A   8  2017-03-30 00:00 2017-03-30 17:50:11 
     2    111A   1  2017-03-31 00:00 2017-03-31 17:53:17 
     3    222B   3  2017-03-31 00:00 2017-03-31 18:42:20 
     4    333C   6  2017-03-31 00:00 2017-03-31 19:27:47 
     5    222B   0  2017-04-01 00:00 2017-04-01 18:12:12 
     6    333C   4  2017-03-31 00:00 2017-04-01 19:38:25 
     7    333C   5  2017-04-01 00:00 2017-04-01 20:31:16 

ft_field_options

list_id option_order option_value option_name 
    1  4    111A   New York 
    1  2    222B   Chicago 
    1  1    333C   Boston 
    1  3    444D   Miami 

Ich mag würde alle Einrichtungen in der ft_field_options Tabelle zeigen (mit einem list_id = 1), die keine Vorlage hatte mit einem Reporting_Datum vom 01.04.2017 in der Tabelle ft_form_1. Jede Einrichtung sollte nur einmal angezeigt werden. In Wirklichkeit werde ich auf Reporting_Dates von 'gestern' schauen wollen. Nochmals vielen Dank für die Unterstützung eines MySQL-Neuling

facility_id option_name option_order  
    111A  New York 3    

Spiel am ft_form_1.facility_id & ft_field_options.option_value

+0

Kommentar entfernen. – Talsma

+0

Siehe https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-very-simple-sql- – Strawberry

Antwort

0

Was ist der Primärschlüssel - Fremdschlüsselbeziehung zwischen zwei Tabellen? Keine Spalte erscheint häufig.

+0

Abfrage ich würde davon ausgehen, eine Verknüpfung auf: ft_form_1.facility_id & ft_field_options.option_value – Talsma

+0

DISTINCT ft_form_1.facility_id SELECT, ft_field_options.option_name, ft_field_options.option_order VON ft_form_1 INNER JOIN ft_field_options oN ft_form_1.facility_id = ft_field_options.option_value WHERE ft_form_1. facility_id NICHT IN (SELECT ft_form_1.facility_id von ft_form_1 WHERE ft_form_1.reporting_date = # 04/01/2017 #); – Praful

+0

hilft das? – Praful

Verwandte Themen