user2874892
user2874892

Reputation:

Novelty SQL code

Okay, I know this is a bit silly but can someone help me?

I'm getting a custom mug printed for someone and want to know if the below makes sense? Is the SQL accurate or is there anyway to improve it or the formatting/naming conventions? They know certainly know SQL.

INSERT INTO dbo.MUG
    SELECT Tea FROM dbo.KITCHEN
    WHERE Milk_Type = 'Semi Skimmed'
    AND Sugar_Count = 0;

Upvotes: 1

Views: 43

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270443

If you are learning SQL, I would recommend that you write the query as:

INSERT INTO dbo.MUG(<column name here>)
    SELECT k.Tea
    FROM dbo.KITCHEN k
    WHERE k.Milk_Type = 'Semi Skimmed' AND k.Sugar_Count = 0;

The most important change is listing the columns after the INSERT. I also think each clause in the SELECT should start on its own line.

Upvotes: 0

Related Questions