我有几个具有完全相同模式的表,它们分开的唯一原因是它们很大。 所以如果我做一个
select * from
(select * from ptable p1
union select * from ptable2 p2
.. and so on) pp
where pid=1234
,这需要很长时间。
我喜欢写一个检查 ptable(s) 的 pid 值 1234,如果它存在,然后从右表中选择行。 我怎么做? pid 是唯一的,只会存在于一张表中,也没有任何排序。
最佳答案
经过一些实验,我设法解决了我的问题,不确定这是否是作为业余爱好者的最佳方式,但它确实有效。
CREATE PROCEDURE 'sproc'(IN pQryID INT)
BEGIN
select count(*) as count into @rowCountp1 from p1 where pid=pQryID;
select count(*) as count into @rowCountp2 from p2 where pid=pQryID;
.. and so on for other similar tables ..
if @rowCountp1>0 THEN
(SELECT * from p1 where pid=pQryID);
elseif @rowCountp2>0 THEN
(SELECT ( from p2 where pid=pQryID);
end if;
END
关于mysql - 如何检查哪个表具有ID并查询其行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41078538/