Sql request for stored procedure

I have five tables "ArtBook, Eng, comm, Law, mgt", and each table has the same column, and I want to look for all the information that a particular book is by its identifier, for example -

select * from ArtBook,Eng,Comm,Law,mgt where @BookId=ArtBooks.BookId
or @BookId=CommBooks.BookId
or @BookId=Eng.BookId
or @BookId=Law.BookId
or @BookId=mgt.BookId
+3
source share
3 answers

If all tables store books of different categories, combine them back into one table and add a category column. Separating into separate tables like this is not a good idea for the reasons you demonstrated.

+3
source
select * 
from ArtBook
where BookId = @BookId
union all
select * 
from Eng
where BookId = @BookId
union all
select * 
from Comm
where BookId = @BookId
union all
select * 
from Law
where BookId = @BookId
union all
select * 
from Mgt
where BookId = @BookId
+1
source

UNION UNION ALL.

(SELECT * FROM ArtBook)
UNION ALL
(SELECT * FROM Eng)
...
WHERE @BookId=ArtBooks.BookId or
       @BookId=CommBooks.BookId or 
       @BookId=Eng.BookId or 
       @BookId=Law.BookId or 
       @BookId=mgt.BookId

et cetera, et cetera. , , .

0

All Articles