A Foreign key referencing multiple unique key
<p>I have 3 tables:</p>

<p>class_a</p>

<pre><code>     CREATE TABLE class_a (
       id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
       std_id INT NOT NULL UNIQUE,
       name varchar(225) NOT NULL)
</code></pre>

<p>class_b</p>

<pre><code>     CREATE TABLE class_b (
       id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
       std_id INT NOT NULL UNIQUE,
       name varchar(225) NOT NULL)
</code></pre>

<p>sn_number</p>

<pre><code>      CREATE TABLE sn_number (
       id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
       pin INT NOT NULL UNIQUE,
       serial VARCHAR(255) NOT NULL UNIQUE,
       std_id INT NULL DEFAULT NULL,
       FOREIGN KEY(std_id) REFERENCES class_a(std_id)
       )
</code></pre>

<p>How can I reference unique <code>std_id</code> in <code>class_a</code> and <code>class_b</code> table as a foreign key in <code>sn_number</code> table.</p>

<p>I want to achieve something like <code>ALTER TABLE sn_number ADD FOREIGN KEY(std_id) REFERENCES class_a(std_id), class_b(std_id)</code></p>

<p>I have tried doing this <code>ALTER TABLE sn_number ADD FOREIGN KEY(std_id) REFERENCES class_a(std_id)</code> </p>

<p>followed by </p>

<p><code>ALTER TABLE sn_number ADD FOREIGN KEY(std_id) REFERENCES class_b(std_id)</code> on <code>sn_number</code> table but will keep overwriting each other.</p>

<p>I have read these:
<a href="https://stackoverflow.com/questions/13311932/foreign-key-referencing-multiple-tables">Foreign Key Referencing Multiple Tables</a> and</p>

<p><a href="https://stackoverflow.com/questions/9780163/composite-key-as-foreign-key-sql/9780198#9780198">Composite key as foreign key (sql)</a>
But I can't find the solution to the problem am having.</p>