{"id":210,"date":"2010-06-03T15:18:36","date_gmt":"2010-06-03T19:18:36","guid":{"rendered":"http:\/\/erics-test-lab.com\/?p=210"},"modified":"2010-06-03T15:18:36","modified_gmt":"2010-06-03T19:18:36","slug":"get-last-record-inserted-without-primary-key-or-id","status":"publish","type":"post","link":"https:\/\/www.esearing.com\/v2010\/2010\/06\/get-last-record-inserted-without-primary-key-or-id\/","title":{"rendered":"Get last record inserted without primary key or id"},"content":{"rendered":"<p>Sometimes we need to get the last record inserted into the database. But if there is no primary key, date, or ID field to query we can use a temp table to return the results we need. <\/p>\n<p>Example:<br \/>\nTable MY_CONTACTS<br \/>\ncontains<br \/>\nContact varchar(100) not null<br \/>\nNote varchar(200) null<\/p>\n<p><code>\/\/select all records into a temp table<br \/>\nselect IDENTITY(int,1,1) AS id, contact, note<br \/>\ninto #tempContacts<br \/>\nfrom MY_CONTACTS<br \/>\n...<br \/>\n\/\/get the last record<br \/>\nselect * from #tempContacts<br \/>\nwhere id =  @@identity<br \/>\n...<br \/>\n\/\/ pull all records to compare results.<br \/>\nselect * from #tempContacts<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes we need to get the last record inserted into the database. But if there is no primary key, date, or ID field to query we can use a temp table to return the results we need. Example: Table MY_CONTACTS &hellip; <a href=\"https:\/\/www.esearing.com\/v2010\/2010\/06\/get-last-record-inserted-without-primary-key-or-id\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,24,14],"tags":[],"class_list":["post-210","post","type-post","status-publish","format-standard","hentry","category-code","category-snippets-quick-code-tips-for-single-elements-attributes-or-details","category-sql"],"_links":{"self":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/comments?post=210"}],"version-history":[{"count":0,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/210\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/media?parent=210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/categories?post=210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/tags?post=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}