Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How to indent SQL statements?

How to indent SQL statements?

Scheduled Pinned Locked Moved Database
databasetutorialquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sacoskun
    wrote on last edited by
    #1

    Hello, I have made a search but could not find how to indent correctly SQL statements. For instance; SELECT * FROM a WHERE att1 IN ( SELECT att8 FROM b WHERE att2 = 10 AND att3 = 20 AND att4 = 30 GROUP BY att8 HAVING count(*) > 3 ) How this sample statement can be indented correctly(standard way)? Any opinion or any article would be appriciated. Kind Regards, Sarp

    C 1 Reply Last reply
    0
    • S sacoskun

      Hello, I have made a search but could not find how to indent correctly SQL statements. For instance; SELECT * FROM a WHERE att1 IN ( SELECT att8 FROM b WHERE att2 = 10 AND att3 = 20 AND att4 = 30 GROUP BY att8 HAVING count(*) > 3 ) How this sample statement can be indented correctly(standard way)? Any opinion or any article would be appriciated. Kind Regards, Sarp

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      I've not come across a standard way of doing this. My particular scheme is something like this:

      SELECT Column1, Column2, Column3
      FROM MyTable AS mt
      INNER JOIN SomeOtherTable AS sot ON mt.pk = sot.fk
      INNER JOIN (SELECT fk, ColumnA, ColumnB, ColumnC
      FROM InnerTable
      WHERE ColumnD = 10) AS it ON mt.pk = it.fk
      WHERE mt.Column4 IS NOT NULL
      ORDER BY Column2;

      ColinMackay.net Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?

      C P 2 Replies Last reply
      0
      • C Colin Angus Mackay

        I've not come across a standard way of doing this. My particular scheme is something like this:

        SELECT Column1, Column2, Column3
        FROM MyTable AS mt
        INNER JOIN SomeOtherTable AS sot ON mt.pk = sot.fk
        INNER JOIN (SELECT fk, ColumnA, ColumnB, ColumnC
        FROM InnerTable
        WHERE ColumnD = 10) AS it ON mt.pk = it.fk
        WHERE mt.Column4 IS NOT NULL
        ORDER BY Column2;

        ColinMackay.net Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?

        C Offline
        C Offline
        CWIZO
        wrote on last edited by
        #3

        I write my SQL like this:

        SELECT
        filed1,
        field2
        FROM
        table1,
        table2
        WHERE
        condition 1
        AND
        contidion 2
        ORDER BY
        field
        LIMIT
        1
        DESC

        Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

        1 Reply Last reply
        0
        • C Colin Angus Mackay

          I've not come across a standard way of doing this. My particular scheme is something like this:

          SELECT Column1, Column2, Column3
          FROM MyTable AS mt
          INNER JOIN SomeOtherTable AS sot ON mt.pk = sot.fk
          INNER JOIN (SELECT fk, ColumnA, ColumnB, ColumnC
          FROM InnerTable
          WHERE ColumnD = 10) AS it ON mt.pk = it.fk
          WHERE mt.Column4 IS NOT NULL
          ORDER BY Column2;

          ColinMackay.net Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?

          P Offline
          P Offline
          Paul Conrad
          wrote on last edited by
          #4

          Colin Angus Mackay wrote:

          My particular scheme is something like

          I do the same here. My old Oracle book from my undergraduate database course does it this way. PJC

          S 1 Reply Last reply
          0
          • P Paul Conrad

            Colin Angus Mackay wrote:

            My particular scheme is something like

            I do the same here. My old Oracle book from my undergraduate database course does it this way. PJC

            S Offline
            S Offline
            sacoskun
            wrote on last edited by
            #5

            Thanks all for your opinions.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups