My database have four tables i.e physics, chemistry, biology and maths respectively. Every table has the same column names like studentName, registrationNumber, mark. My question is when I search with registrationNumber I want to get every fields of mark in every table. How can I query such a way? Please explain it with simple example. Thanks in advance (this example is only for the problem presenting purpose only)
You should use normalization to store the marks in single table instead of making different table for each subject Normalization
I agree with @NareshKumar that normalization is one option. But if you must use your current schema you could do a UNION
query:
SELECT studentName, registrationNumber, mark, 'physics' AS class
FROM physics
WHERE registrationNumber = N
UNION ALL
SELECT studentName, registrationNumber, mark, 'chemistry' AS class
FROM chemistry
WHERE registrationNumber = N
SELECT studentName, registrationNumber, mark, 'biology' AS class
FROM biology
WHERE registrationNumber = N
SELECT studentName, registrationNumber, mark, 'maths' AS class
FROM maths
WHERE registrationNumber = N
It seems we've had the same idea with @Tim Biegeleisen
and he did it better, so I will just redirect you to his answer.