如果您追求优雅的SQL,则可以使用行构造函数:
SELECt * FROM email_phone_notes WHERe (email, phone) IN ( ('foo@bar.com' , '555-1212'), ('test@test.com', '888-1212') -- etc.);
但是,这根本不是索引友好的,也不建议在任何大的表上使用。取而代之的是,您可以实现具有所需对的表,然后将其与表连接:
SELECt * FROM email_phone_notes NATURAL JOIN ( SELECt 'foo@bar.com' AS email, '555-1212' AS phoneUNIOn ALL SELECT 'test@test.com', '888-1212'-- etc.) t;
否则预填充(临时)表:
CREATE TEMPORARY TABLE foo (PRIMARY KEY (email, phone)) Engine=MEMORY SELECT email, phone FROM email_phone_notes WHERe FALSE;INSERT INTO foo (email, phone)VALUES ('foo@bar.com' , '555-1212'), ('test@test.com', '888-1212') -- etc.;SELECt * FROM email_phone_notes NATURAL JOIN foo;
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)