tag:blogger.com,1999:blog-8712770457197348465.post7019774272895169203..comments2024-03-28T02:47:19.159-07:00Comments on Javarevisited: A Better way to write Complex SQL queries for Programmersjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger13125tag:blogger.com,1999:blog-8712770457197348465.post-60849576533335072672021-02-19T07:24:40.573-08:002021-02-19T07:24:40.573-08:00Hello Mladen, If you can do that on regular basis ...Hello Mladen, If you can do that on regular basis then yes, that's the bestjavin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-88359617826362447212021-02-08T02:29:36.264-08:002021-02-08T02:29:36.264-08:00Personally I've found the best way is to use a...Personally I've found the best way is to use a sql formatter like the one built into Red Gate's SQL Prompt or the open source Poor Man's SQL Formatter https://poorsql.com/ - that way the sql formatting stays consistent and if you're checking sql into source control it makes changes a lot easier to track.Mladenhttps://www.blogger.com/profile/07312482820383206150noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-82107760496495097822021-02-04T20:45:55.020-08:002021-02-04T20:45:55.020-08:00Thank you Shardrach and Anonymous, yes formatting ...Thank you Shardrach and Anonymous, yes formatting is key while writing long SQL queries. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-17613024417235510442021-01-30T23:33:57.719-08:002021-01-30T23:33:57.719-08:00NiceNiceAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-77449226808692160832020-08-29T20:43:39.902-07:002020-08-29T20:43:39.902-07:00Nice tutorial. I highly concur with this . sometim...Nice tutorial. I highly concur with this . sometimes I find myself spending over 10 minutes trying to understand long queries simplely because they are not formatted right.shadrachhttps://www.blogger.com/profile/02940657831233087635noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-21626475093999469112017-01-22T17:18:16.144-08:002017-01-22T17:18:16.144-08:00Hello @rvt, I agree with you. Actually some typo l...Hello @rvt, I agree with you. Actually some typo left, e.emp_id = d.dept_id should be read as e.dept_id = d.dept_id, a key column between these two table where dept_id is the primary key in Department but foreign key in Employee. Similarly, p.project_name come from Project table which represent the relationship between Employee and Project, again project_id is primary key in Project table and javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-53616420922948834702017-01-22T09:32:57.694-08:002017-01-22T09:32:57.694-08:00I also think that the upper case for SQL keywords ...I also think that the upper case for SQL keywords is not a bad thing at all. <br />The 'Department' and Employee with uppercase really bug's me here. That is camel case mixing with underscore_case. <br />Joining on e.emp_id = d.dept_id sounds very fishy, why would you want a employment id being joined on department id?? Or perhaps is your naming all goovy? Where project_name comes Anonymoushttps://www.blogger.com/profile/02339858060484986825noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-79842504788056499682017-01-22T06:05:04.611-08:002017-01-22T06:05:04.611-08:00I agree with @Badal that you should make all the s...I agree with @Badal that you should make all the sql text lower case and keywords upper case to help distinguish between key words and table names. Nice tutorial.CSC Programmerhttp://www.cscprogrammingtutorials.comnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-9230379015701047572017-01-16T06:46:33.362-08:002017-01-16T06:46:33.362-08:00If you want to run query by commenting conditions,...If you want to run query by commenting conditions, you better write <br />where 1=1<br />and id > 100<br />and name like '%s%'Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-82124936678441471232017-01-15T05:21:13.569-08:002017-01-15T05:21:13.569-08:00I always put the new table name first in a join cl...I always put the new table name first in a join clause, not second. That way the join looks more consistent if you're joining to Table c with clauses correlating to Table a and Table b, and if you have a simple join constraint on c, e.g. "<br />LEFT JOIN c <br />ON c.foo = a.foo <br />AND c.bar = b.bar <br />AND c.baz LIKE 'A%'Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-20170427404253361042017-01-14T07:59:45.257-08:002017-01-14T07:59:45.257-08:00You have barely scratched the surface of SQL at th...You have barely scratched the surface of SQL at this point. What about subqueries?Turnkey Solutionshttps://www.blogger.com/profile/10571384651160763350noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-76509684468649167872017-01-14T01:10:54.105-08:002017-01-14T01:10:54.105-08:00I think upper case sql keywords are not bad. If th...I think upper case sql keywords are not bad. If there is no sql highlighting available (maybe the sql is embedded in another language or just an email) then it's much easier to read. I also prefer indentation in some cases.Mladenhttps://www.blogger.com/profile/07312482820383206150noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-82451103948202623612017-01-12T07:46:09.601-08:002017-01-12T07:46:09.601-08:00Nice post. 1 additional input: make all the sql te...Nice post. 1 additional input: make all the sql text lower case and keywords upper case. it can help distinguish between key words and column/table names. <br /><br />In SQL Developer, can be easily achieved by:<br />1. Ctrl + Shift + ' (change case)<br />2. Ctrl + F7 (Format: keywords are changed to uppercase)Badal Chowdharyhttps://www.blogger.com/profile/11687157117986321384noreply@blogger.com