On Wed, January 24, 2007 8:07 pm, Robert Cummings wrote: > On Wed, 2007-01-24 at 18:23 -0600, Richard Lynch wrote: >> On Wed, January 24, 2007 7:41 am, Roman Neuhauser wrote: >> > # [EMAIL PROTECTED] / 2007-01-24 13:57:03 +0200: >> >> and also in these days I'm looking for 19 inch (or more) wide LCD >> >> sceerns to able to fit longer lines in my screen... >> > >> > Number of reading errors people make grows with line length, >> > this has been known for as long as I remember. You're increasing >> the >> > probability of bugs in the code, and get tired sooner because >> > following >> > long lines requires more energy. >> >> I believe those results are specific to what is being read. >> >> Surely it's easier to read: >> >> SELECT blah, blah, blah, blah, blah, blah, blah, blah, blah >> >> if it's all on one line, no matter how many fields there are, while >> trying to read the code as a whole. >> >> Sure, it can be "hard" to find/read the individual field names, on >> the >> rare occasion that you need to do that... > > Dear Mr Lynch, normally I highly respect your commentary on the list, > but today I think you've been-a-smoking the crackpipe a tad too much. > > There is no way in hell one long line of SQL is easier to read than > formatted SQL that clearly delineates the clause structure. > > SELECT A.field1 AS afield1, A.field2 AS afield2, B.field1 AS bfield1, > B.field2 AS bfield2, C.field1 AS cfield1, C.field2 AS cfield2, > D.field1 > AS dfield1, D.field2 AS dfield2 FROM tableA as A LEFT JOIN tableB AS B > ON B.fee = A.foo LEFT JOIN tableC AS C ON C.fii = B.fee LEFT JOIN > tableD > AS D ON D.fuu = C.fii WHERE A.foo = 'someValue' ORDER BY afield1 ASC, > cfield2 ASC > > The above line "should" be on one line, but my email client might > autowrap it. Either way, the following is formatted and is much > clearer. > > SELECT > A.field1 AS afield1, > A.field2 AS afield2, > B.field1 AS bfield1, > B.field2 AS bfield2, > C.field1 AS cfield1, > C.field2 AS cfield2, > D.field1 AS dfield1, > D.field2 AS dfield2 > FROM > tableA as A > LEFT JOIN tableB AS B ON > B.fee = A.foo > LEFT JOIN tableC AS C ON > C.fii = B.fee > LEFT JOIN tableD AS D ON > D.fuu = C.fii > WHERE > A.foo = 'someValue' > ORDER BY > afield1 ASC, > cfield2 ASC > > > While the above is contrived, most of us know such examples happen > quite > often in the wild. Not only is it easier to read, but the task of > adding > or removing selected fields is trivial.
I meant ONLY the SELECT part on a single line. Only a moron would cram the FROM and all that into the same line. :-) $query = "SELECT blah1, blah2, blah3, ... blah147 "; $query .= " FROM table1 "; $query .= " LEFT OUTER JOIN table2 "; $query .= " ON blah7 = blah42 "; $query .= " WHERE blah16 "; $query .= " AND blah42 "; $query .= " ORDER BY blah9, blah8 desc, blah6 "; is what I go for. The SELECT line is the only one that ever gets all that long, really... -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php