We use hibernate to handle different databases. There's a problem about using pair comparison sql when the data source is MS SQL. We want to know how to convert this statement for ms sql.
The following is the simplified sql.
notice:
- column1 and column2 both are uuid and numeric type. ( in ms sql will be numeric(19,0)
- the converted sql statement should be follow the form -- WHERE condition IN sub-query
- new statement should take execution performance into consideration.
code:
select * from table1 t1
where (t1.column1, t1.column2) in
select ( sub.column1, sub.column2) from table2 sub
where sub.column3 = $var
the following is my trial I'm afraid of its low performance on string comparison and making index no effect.
SELECT *
FROM TABLE_1 T1
WHERE CAST(COL1 AS VARCHAR(19))+CAST(COL2 AS VARCHAR(19))
IN (SELECT CAST(COL1 AS VARCHAR(19))+CAST(COL2 AS VARCHAR(19))
FROM TABLE_2 T2
WHERE T2.COL3 = 'A')
is there any suggestion for us? thanks a lot!!