I'm still in the process of learning SQL queries. I've tried searching around online, but I don't even know what terms I should be searching for, so I'm looking for someone to point me in the right direction. I have two tables -- appointments and logins. I'm trying to use the concat function to get the first and last name for both "apptFor" and "addedBy." Do I need to have separate queries? It seems like it should be able to get done in a single query.
<table border="1">
<tbody>
<tr>
<td width="140" align="center"><strong>Appt Date/Time</strong></td>
<td width="100" align="center"><strong>Appt For</strong></td>
<td width="300" align="center"><strong>Appointment</strong></td>
<td width="100" align="center"><strong>Added By</strong></td>
<td width="100" align="center"><strong>Date Added</strong></td>
</tr>
<?php
$query = "SELECT a.appID,a.appDate,a.appNote,a.apptFor,a.addedBy,a.added,concat(u.firstName,' ',u.lastName) as appAddedBy FROM appointments a ";
$query .=" INNER JOIN logins u on a.addedBy=u.userid WHERE a.userID='$uid' order by appDate asc";
$result = mysqli_query($con, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
?>
<tr>
<td><?php echo $row['appDate']; ?></td>
<td><?php echo $row['apptFor']; ?></td>
<td><?php echo $row['appNote']; ?></td>
<td><?php echo $row['appAddedBy']; ?></td>
<td><?php echo $row['added']; ?></td>
</tr>
<?php }} ?>
</tbody>
</table>
JOINthe same table more than once by using different aliases.