0

I want to the following using prepared statements:

<?php 

$sql = "SELECT name FROM B WHERE profile_id IN (SELECT profile_id FROM A WHERE login_id='$email')
    UNION SELECT name FROM C WHERE profile_id IN (SELECT profile_id FROM A WHERE login_id='$email')";

$result = mysqli_query($conn,$sql);

?>

Here, A is the main table, B and C are sub tables. In the main table, the primary key is profile_id. The tables B and C have a foreign key referencing A's profile_id.

Karthikeyan
  • 143
  • 1
  • 2
  • 9

1 Answers1

0
SELECT x.name 
  FROM A 
Join 
 ( Select Name,profile_id from b
   Union all
   Select name, profile_id from c
 ) x
 On 
  x. profile_id = a.profile_id
 WHERE a.login_id= :email
Strawberry
  • 33,750
  • 13
  • 40
  • 57