Question: I am trying to render two different components based on the click event that gets passed the text of the button in React. I know how to do it in the function, but how do I render the DOM element based on the click event? so far I have:

```
const Popup: React.FunctionComponent = () => {

    const [visible, setVisible] = React.useState<boolean>(false);

    const toggleDialog = (e: React.MouseEvent<HTMLButtonElement>) => {
        if (e.currentTarget.textContent === 'Primary') {
            setVisible(!visible);
            console.log(e.currentTarget.textContent);
            return (
               <div>
               <p>{e.currentTarget.textContent}</p>
               </div>
            )
        } else {
            console.log(e.currentTarget.textContent);
            setVisible(!visible);
            return (
                <div>
                <p>{e.currentTarget.textContent}</p>
                </div>
            )
        }
    };

    const closeDialog = () => {
        setVisible(false);
    };

    return (
        <>
            <Button variant="primary" onClick={toggleDialog}>Primary</Button>
            <Button variant="secondary" onClick={toggleDialog}>secondary</Button>
            {visible && <Dialog title={"Please confirm"} onClose={closeDialog}>
                {toggleDialog}
                <DialogActionsBar>
                    <button className="button" onClick={toggleDialog}>No</button>
                    <button className="button" onClick={toggleDialog}>Yes</button>
                </DialogActionsBar>
            </Dialog>}
        </>
    )
}

export default Popup;

```

Answer: 
This is fairly straightforward `join` logic:

Query
=====

```
declare @t table(Class int,Teacher varchar(10),Subject varchar(10));
insert into @t values
 (1,'Adam','English')
,(2,'Bill','Maths')
,(3,'Carl','Maths')
,(4,'Dave','Science')
,(5,'Evan','Maths')
;

select c.Class
      ,s.Teacher
      ,s.Subject
from @t as c
    join @t as s
        on c.Subject = s.Subject
order by c.Class
         ,s.Teacher;

```

Result
======

| Class | Teacher | Subject |
| --- | --- | --- |
| 1 | Adam | English |
| 2 | Bill | Maths |
| 2 | Carl | Maths |
| 2 | Evan | Maths |
| 3 | Bill | Maths |
| 3 | Carl | Maths |
| 3 | Evan | Maths |
| 4 | Dave | Science |
| 5 | Bill | Maths |
| 5 | Carl | Maths |
| 5 | Evan | Maths |
**Use below code**

```
SELECT TBL.CLASS,ISNULL(X.TEACHER,TBL.TEACHER) TEACHER,TBL.SUBJECTS FROM 
TeachingSets as TBL LEFT JOIN (
SELECT * FROM TeachingSets WHERE SUBJECTS='MATHS'
)X ON  TBL.SUBJECTS=X.SUBJECTS

```