<div dir="ltr"><div>I thought I'd share something I learned this morning about MySQL.</div><div>The topic is using information in a table in the same query that is inserting that information into the table.  Whenever I forget that MySQL doesn't like that it trips me up.  I saw it happen recently in a Koha database update, so it was on my mind.</div><div>Today I found out that it can be done if table aliases are used in the subquery.  I was working on an entirely different software when it tripped me up again, but I decided to see if there was a way after all.</div><div>Here's the query I ended up with, that works in recent versions of MySQL, as an example:</div><div><br></div><div>insert into users (group_id,handle,name,email,user_notify,password,security_level,landing_page,ldap_username,restricted_leaderboard,search,ticketSelectLimit) (select 33,'user2',<a href="http://u2.name">u2.name</a>,u2.email,u2.user_notify,u2.password,u2.security_level,u2.landing_page,h2.ldap_username,h2.restricted_leaderboard,h2.search,h2.ticketSelectLimit from users as u2 where handle = 'user' );</div><div><br></div><div><br>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div>Michael Hafen<br></div>Washington County School District Technology Department<br></div>Systems Analyst<br><br></div></div></div></div></div></div>