The thing is, both tables do have primary keys, and I haven’t had any problems so far with any other standard SELECTS/INSERTS at all. I’m new to JOINS, but I can’t see why this isn’t working.
I’m get this error message:
org.postgresql.util.PSQLException: No primary key found for table devicetable.
However, the primary keys for both tables are the columns I’m selecting for: deviceid / username. Perhaps this has something to do with it?
I’m accessing it via JDBC
PreparedStatement query = curSQL.getConn().prepareStatement("SELECT devicetable.pushid FROM devicetable, usertable WHERE usertable.username=? AND usertable.deviceid = devicetable.deviceid", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
query.setString(1, username);
ResultSet rs = query.executeQuery();
if (rs.next()){
rs.updateString("pushid", pushID);
rs.updateRow();
}
rs.close();
query.close();
With the SQL:
SELECT devicetable.pushid FROM devicetable, usertable
WHERE usertable.username=?
AND usertable.deviceID = devicetable.deviceID
Try an explicit join: