{"id":91,"date":"2012-06-01T11:12:00","date_gmt":"1970-01-01T00:00:00","guid":{"rendered":"http:\/\/www.yazilimmutfagi.com\/?p=91"},"modified":"2012-06-01T11:12:00","modified_gmt":"1970-01-01T00:00:00","slug":"bir-kolon-aliasini-where-ve-order-by-icinde-kullanmak","status":"publish","type":"post","link":"https:\/\/www.yazilimmutfagi.com\/index.php\/2012\/06\/01\/bir-kolon-aliasini-where-ve-order-by-icinde-kullanmak\/","title":{"rendered":"Bir Kolon ALIAS&#8217;ini Where ve Order by I\u00e7inde Kullanmak"},"content":{"rendered":"<p>Olusturdugumuz sorgularda neredeyse hepimiz where ve order by gibi kisimlarda kolon alias larini kullanmaya \u00e7alismisizdir. Where c\u00fcmlesi i\u00e7inde kullanmak istedigimiz de hata alirken order by i\u00e7inde kullandigimiz da hata almiyoruz. Peki bunun nedeni nedir?<\/p> \n<p>Ilk olarak iki \u00f6rnekle olayi anlatmaya \u00e7alisayim.<\/p>\n<h3>Where i\u00e7inde Alias kullanmak:<\/h3>\n<pre class=\"brush:sql\">\nselect \n\tname as ObjeAdi, \n\tYEAR(create_date) as YIL,\n\tcreate_date as OlusturmaTarihi\nfrom \n\tsys.objects\nwhere YIL = 2012\n<\/pre>\n<p>Yukaridaki sorguyu \u00e7alistirdiginiz zaman &#8220;Invalid column name &#8216;YIL&#8217;.&#8221; hatasi alirsiniz.<\/p>\n\n<h3>Order by I\u00e7inde Kullanimi :<\/h3>\n<pre class=\"brush:sql\">\nselect \n\tname as ObjeAdi, \n\tYEAR(create_date) as YIL,\n\tcreate_date as OlusturmaTarihi\nfrom \n\tsys.objects\norder by YIL desc\n<\/pre>\n<p>Yukaridaki sorguyu ise herhangi bir hata almadan \u00e7alistirabilirsiniz. Peki bunun sebebi nedir ?<\/p>\n<p>SQL Server bir sorguyu islerken belirli bir siraya g\u00f6re islem yapar. Bu sira genel hatlari ile su sekildedir. FROM -> ON -> WHERE -> SELECT -> ORDER BY\n<\/p>\n<p>Sizin tanimladiginiz YIl alias i select i\u00e7inde tanimlandigi ve WHERE kismi SQL de SELECT&#8217;ten \u00f6nce \u00e7alistigi i\u00e7in, WHERE kismi \u00e7alisirken SQL engine daha YIL adindaki aliasin ne oldugunu bilmemekte. Bu y\u00fczden de invalid column name hatasi vermekte.<\/p>\n<p>\nORDER BY ise SELECT&#8217;ten sonra \u00e7alistigi i\u00e7in bu kisimda artik YIl aliasi SQL engine tarafindan taninmaktadir. Buda hata almadan sorgumuzun tamamlanmasini saglamaktadir.\n<\/p>","protected":false},"excerpt":{"rendered":"<p>Olusturdugumuz sorgularda neredeyse hepimiz where ve order by gibi kisimlarda kolon alias larini kullanmaya &#231;alismisizdir. Where c&#252;mlesi i&#231;inde kullanmak istedigimiz de hata alirken order by i&#231;inde kullandigimiz da hata almiyoruz. Peki bunun nedeni nedir?<\/p>\n","protected":false},"author":517,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[422],"tags":[4292,4484,5224,5041],"_links":{"self":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/posts\/91"}],"collection":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/users\/517"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/comments?post=91"}],"version-history":[{"count":0,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/posts\/91\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/media?parent=91"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/categories?post=91"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yazilimmutfagi.com\/index.php\/wp-json\/wp\/v2\/tags?post=91"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}