Peter58 Posted February 29, 2020 Share Posted February 29, 2020 Hi, i have a problem with my sql query, I tried everything but until now not the right results. Problem : I have two tables, One that is called Alarms and the other one Logs. From Alarms I want to use the fields Machine, Message en datetime which is in 2020-02-27 19:11:54:123 format. In the table Logs I have the fields Anode and Datetime also in 2020-02-27 19:11:54:123 format. When a alarms occurs I want to use the datetime field to look for the Anode in the other table Logs with the same Datetime value but only on the whole second, I want only one value back. So the ouput would be someting like Machine, Message ,Datetime,Anode I believe I have to use the LEFT JOIN instruction : SELECT Machine,Message,DateTime,Anode FROM Table1.Alarms LEFT JOIN Logs ON table1.DateTime = table2.DateTime; Can Anyone help me with this ? Thanks in advance, Peter Link to comment Share on other sites More sharing options...
dsonesuk Posted March 1, 2020 Share Posted March 1, 2020 Add WHERE clause where the 'second' value matches Using MSSQL - DATEPART() https://www.w3schools.com/sql/func_sqlserver_datepart.asp OR MYSQL - SECOND() https://www.w3schools.com/sql/trymysql.asp?filename=trysql_func_mysql_second Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now