Sql

Structured Query Language (SQL) is a language for querying databases. Questions should include code examples, table structure, sample data, and a tag for the DBMS implementation (e.g. MySQL, PostgreSQL, Oracle, MS SQL Server, IBM DB2, etc.) being used. If your question relates solely to a specific DBMS (uses specific extensions/features), use that DBMS's tag instead. Answers to questions tagged with SQL should use ISO/IEC standard SQL.

62 votes
13 answers
1.7K views
When to use single quotes, double quotes, and backticks in MySQL

I am trying to learn the best way to write queries. I also understand the importance of being consistent. Unti

avatar
Sydney
0 1 0 9
asked 07 September, 2021
52 votes
15 answers
1.4K views
How do I see what character set a MySQL database / table / column is?

What is the (default) charset for: MySQL database MySQL table MySQL column

avatar
Keith
0 1 0 9
asked 07 September, 2021
59 votes
15 answers
337 views
MySQL Query GROUP BY day / month / year

Is it possible to make a simple query to count how many records I have in a determined period of time like a y

avatar
Lashawna
0 1 0 9
asked 07 September, 2021
57 votes
10 answers
1.8K views
How can I temporarily disable a foreign key constraint in MySQL?

Is it possible to temporarily disable constraints in MySQL? I have two Django models, each with a foreign key

avatar
Hildegard
0 1 0 9
asked 07 September, 2021
53 votes
7 answers
2.7K views
'IF' in 'SELECT' statement - choose output value based on column values

SELECT id, amount FROM report I need amount to be amount if report.type='P' and -amount if report.

avatar
Keila
0 1 0 9
asked 07 September, 2021
56 votes
15 answers
1.7K views
How can I do a FULL OUTER JOIN in MySQL?

I want to do a full outer join in MySQL. Is this possible? Is a full outer join supported by MySQL?

avatar
Alba
0 1 0 9
asked 07 September, 2021
53 votes
4 answers
2.2K views
SQL query to prepend prefix to existing value in a field

I have searched and searched for an answer to this, and I think this must be child's play for anyone who

avatar
Emilia
0 1 0 9
asked 07 September, 2021
62 votes
23 answers
2.2K views
Entity Framework. Delete all rows in table

How can I quickly remove all rows in the table using Entity Framework? I am currently using: var rows = from o

avatar
Boyd
0 1 0 9
asked 07 September, 2021
55 votes
17 answers
1.9K views
Validation failed for one or more entities while saving changes to SQL Server Database using Entity Framework

I want to save my Edit to Database and I am using Entity FrameWork Code-First in ASP.NET MVC 3 / C# but I am g

avatar
Scot
0 1 0 9
asked 07 September, 2021
59 votes
6 answers
1.2K views
Postgres error: null value in column "id" - during insert operation

I use postgresql and yii2 framework. Well I got a very interesting error message: SQLSTATE[23502]: Not null v

avatar
Charis
0 1 0 9
asked 07 September, 2021
59 votes
2 answers
2.9K views
Matching all values in IN clause

Is there a way to ensure all values in an IN clause are matched? Example: I can use IN as: IN (5,6,7,8). I

avatar
Solomon
0 1 0 9
asked 07 September, 2021
49 votes
15 answers
2.1K views
#1273 – Unknown collation: ‘utf8mb4_unicode_520_ci’

I have a WordPress website on my local WAMP server. But when I upload its database to live server, I get error

avatar
Sachiko
0 1 0 9
asked 07 September, 2021
61 votes
16 answers
2K views
DateTime2 vs DateTime in SQL Server

Which one: datetime datetime2 is the recommended way to store date and time in SQL Server 2008+? I'm a

avatar
Hallie
0 1 0 9
asked 07 September, 2021
57 votes
22 answers
2.4K views
How can I get column names from a table in SQL Server?

I want to query the name of all columns of a table. I found how to do this in: Oracle MySQL PostgreSQL But I a

avatar
Emilia
0 1 0 9
asked 07 September, 2021
55 votes
27 answers
2.1K views
How can I list all foreign keys referencing a given table in SQL Server?

I need to remove a highly referenced table in a SQL Server database. How can I get a list of all the foreign

avatar
Thurman
0 1 0 9
asked 07 September, 2021
51 votes
11 answers
2.7K views
How to Join to first row

I'll use a concrete, but hypothetical, example. Each Order normally has only one line item: Orders: Or

avatar
Gigi
0 1 0 9
asked 07 September, 2021
56 votes
14 answers
2.4K views
Should I use != or <> for not equal in T-SQL?

I have seen SQL that uses both != and <> for not equal. What is the preferred syntax and why? I like !=

avatar
Lorenzo
0 1 0 9
asked 07 September, 2021
61 votes
21 answers
1.2K views
How can I SELECT rows with MAX(Column value), PARTITION by another column in MYSQL?

My table is: id home datetime player resource 1 10 04/03/2009 john 399 2 11 04/03/2009 juliet 244 5 12 04/03/

avatar
Lawanda
0 1 0 9
asked 07 September, 2021
57 votes
30 answers
902 views
Exclude a column using SELECT * [except columnA] FROM tableA?

We all know that to select all columns from a table, we can use SELECT * FROM tableA Is there a way to excl

avatar
Patsy
0 1 0 9
asked 07 September, 2021
55 votes
21 answers
1.7K views
Function vs. Stored Procedure in SQL Server

I've been learning Functions and Stored Procedure for quite a while but I don't know why and when I

avatar
Keila
0 1 0 9
asked 07 September, 2021