I need help with a SQL statement. I have never worked with INNER JOIN and I can not do it correctly.
As you can see in the previous image, what I'm looking for is this:
id_invitacion
of the table invitacion
id_invitado
with nombre
of table invitado
, is
say, instead of saving the id_invitado
, I want to receive the
String found in the column nombre
id_evento
with the table evento
, that is, instead of saving the id_evento
, I want to receive the String that is in the column nombre
To save the data, I have this code:
int i = 0;
do {
registros[i][0] = rs.getInt("id_invitacion");
registros[i][1] = rs.getString("nombreEvento");
registros[i][2] = rs.getString("nombreInvitado");
i++;
} while (rs.next());
So far this is the sentence that I created but, it does not work for me:
sSQL = "SELECT evento.nombre AS nombreEvento FROM evento "
+ ", invitado.nombre AS nombreInvitado FROM invitado "
+ "INNER JOIN invitacion ON evento.id_evento = invitacion.id_invitado "
+"WHERE evento.nombre LIKE '%" + buscar + "%' ORDER BY id_invitacion";
Error I receive:
You have an error in your SQL syntax
Any help will be welcome.