Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6191821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:50:02+00:00 2026-05-24T02:50:02+00:00

When I make a SQL query, for example, in database where there’s a table

  • 0

When I make a SQL query, for example, in database where there’s a table named “employees”, which is the best practice of writing?

SELECT 'name', 'surname', 'phone' WHERE 'city'='ny' FROM 'employees' ORDER BY 'name'

SELECT name, surname, phone, WHERE city=ny FROM employees ORDER BY name

or

SELECT employees.name, employees.surname WHERE employees.city=ny ORDER BY employee.name

And why? Is there a standard for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:50:02+00:00Added an answer on May 24, 2026 at 2:50 am

    IMHO, the best standard is this:

    select
        o.name as office_name,
        e.name as employee_name,
        count(*) as count
    from employee e
    left join office o on o.id = e.office_id
    where e.name like 'a%'
    group by 1
    order by 1
    

    Your goal is improved clarity and maintenance. The features/benefits demonstrated here are:

    • Nothing in uppercase (ie select not SELECT)
    • Only use backtick escapes for reserved words
    • Table names in singular (ie employee not employees)
    • View names in the plural (eg current_employees)
    • Underscores separating name parts (ie no camelCase or flatcase etc)
    • Primary keys always named id
    • Foreign keys always named table_id
    • Where column names collide in a query, aliased them as <table>_<column>
    • Queries are formatted as above
      • Left justified, except columns, which are eash on their own line
      • Line breaks on major keywords
    • Table aliases generally using all first letters of name parts, eg my_table_name mtn
    • Group by and order by preferring numbers over expressions (if you change the expression, you don’t need to the group by or order by clauses, otherwise you’re violating the DRY principle)

    This comes from many years of coding SQL and I’ve found this makes things easiest.

    If you always have a consistent format, you’ll find syntax errors easier to find too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to make a query to my database with LINQ to SQL. example
I'd like to make an (MS)SQL query that returns something like this: Col1 Col2
I`m parsing SQL query with C# Regex. I need also to make my pattern
My boss asks me to write only ANSI SQL to make it database independent.
In a SQL-database I make some selects, that get an duration (as result of
In SQL, How we make a check to filter all row which contain a
How do you make a field in a sql select statement all upper or
The classic way to query an SQL database case-insensitively from Java is as follows:
I want to make a program that pulls objects from a sql database and
How can I make a SQL Compact 2008 application for the desktop? I know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.