SQL to get, inserting new entry if absent
===

I'm not sure if this question is properly in the domain of SQL, MySQL, stored routines or even JDBC.  Basically I want a SQL function that looks like:

    INSERT IGNORE (id, data) INTO table
    SELECT id FROM table WHERE `data` = data

This needs to be initiated from Java via raw SQL or a stored routine.  This looks incredibly poor because if the `insert ignore` succeeds, it shouldn't have to follow right up with a SQL query to get what it just interested.  Note that `id` will be autogenerated. Best way to do this that's efficient on the # of SQL queries and readable and such?  I don't really have any idea how efficient an INSERT IGNORE is.
    
        