sql server - WHERE - Display value in Column1 only if matches value in Column2 -


i have 2 columns of date/time data, 1 table. column1 has multiple values , 1 displayed in query. column2 have 1 date/time value matches recent value column1. i'm interested in displaying matched value, in column1.

column1 2014-03-08 00:00:00.000 2014-03-08 00:00:00.000 2014-03-08 09:03:00.000 2014-03-10 01:58:00.000  column2 2014-03-10 01:58:00.000 

the data/time value varies day day can't write statement based on specific time stamp. recent value in column1 display if matches other in column2. conventional thinking be:

where column1 = 'column2'  or column1 >= 'column2' <-- since never greater 

i error:

conversion failed when converting date and/or time character string

. both values yyyy-mm-dd hh:mm:ss:ms format.

try this:

select t1.column1 table1 t1 inner join table1 t2 on t1.column1 = t2.column2 

for where column1 = column2 work, values has in same row. query not assume that.

you do:

select column1 table1  column1 in (select column2 table1) 

sample sql fiddle


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -