Currently Attempting to Optimize SQL queries. Need help! Details below : I'm currently attempting to optimize some SQL queries in a VB format (Ancient, I know) but I'm just attempting to make the queries more efficient.
This is an example of how some of the queries are now

    "SELECT DISTINCT Appointments.WithID, Users.LastName, Users.FirstName"
    " FROM Appointments INNER JOIN AppointmentTypes ONAppointmentTypes.ID = 
    Appointments.AppTypeID "
    " INNER JOIN Users ON Users.ID = Appointmens.WithID"
    "WHERE Appointments.Hide = 0"
    "ORDER BY Users.LastName, Users.FirstName"

Above is the initial query that runs, then for all of the results, which generally are the returned Appointments.WithID, A for each loop happens for each item where another query is run, for example below

    "SELECT Appointments.CustomerID FROM Appointments"
    "WHERE Appointments.Hide = 0"
    "AND Appointments.WithID = (And this is where the "Appointment.WithID"'s 
    from the previous query are entered)

So I'm not sure if I explained this properly or not BUT all in all, the second query is run multiple times for EACH Appointment.WithID which is found from the first query. I need a way where I can incorporate the second query within the first so it doesnt run the second query hundreds of times depending on the amount of WithID's returned

Any help would be appreciated