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.

63 votes
16 answers
2.6K views
How can I do an UPDATE statement with JOIN in SQL Server?

I need to update this table in SQL Server with data from its 'parent' table, see below: Table: sale

avatar
Freida
0 1 0 9
asked 07 September, 2021
63 votes
15 answers
385 views
How can I delete using INNER JOIN with SQL Server?

I want to delete using INNER JOIN in SQL Server 2008. But I get this error: Msg 156, Level 15, State 1, L

avatar
Jefferey
0 1 0 9
asked 07 September, 2021
54 votes
22 answers
1.2K views
What is the difference between UNION and UNION ALL?

What is the difference between UNION and UNION ALL?

avatar
User demo
0 1 0 9
asked 07 September, 2021
52 votes
28 answers
2.1K views
Insert into ... values ( SELECT ... FROM ... )

I am trying to INSERT INTO a table using the input from another table. Although this is entirely feasible for

avatar
Basil
0 1 0 9
asked 07 September, 2021
55 votes
18 answers
1.4K views
Select first row in each GROUP BY group?

As the title suggests, I'd like to select the first row of each set of rows grouped with a GROUP BY. Spec

avatar
Juliane
0 1 0 9
asked 07 September, 2021
57 votes
30 answers
1.9K views
How do I perform an IF...THEN in an SQL SELECT?

How do I perform an IF...THEN in an SQL SELECT statement? For example: SELECT IF(Obsolete = 'N' OR

avatar
Joseph
0 1 0 9
asked 07 September, 2021
49 votes
30 answers
1.3K views
How to query MongoDB with "like"

I want to query something with SQL's like query: SELECT * FROM users WHERE name LIKE '%m%' Ho

avatar
Shanita
0 1 0 9
asked 07 September, 2021
62 votes
30 answers
1.3K views
Insert results of a stored procedure into a temporary table

How do I do a SELECT * INTO [temp table] FROM [stored procedure]? Not FROM [Table] and without defining [temp

avatar
Chelsea
0 1 0 9
asked 07 September, 2021
60 votes
30 answers
2.9K views
How to return only the Date from a SQL Server DateTime datatype

SELECT GETDATE() Returns: 2008-09-22 15:24:13.790 I want that date part without the time part: 2008-09-22 0

avatar
Corrin
0 1 0 9
asked 07 September, 2021
67 votes
30 answers
890 views
How to concatenate text from multiple rows into a single text string in SQL Server

Consider a database table holding names, with three rows: Peter Paul Mary Is there an easy way to turn this i

avatar
Xavier
0 1 0 9
asked 07 September, 2021
57 votes
30 answers
751 views
Finding duplicate values in a SQL table

It's easy to find duplicates with one field: SELECT name, COUNT(email) FROM users GROUP BY email HAVING

avatar
Elicia
0 1 0 9
asked 07 September, 2021
50 votes
30 answers
1.3K views
How do I import an SQL file using the command line in MySQL?

I have a .sql file with an export from phpMyAdmin. I want to import it into a different server using the comma

avatar
Sydney
0 1 0 9
asked 07 September, 2021
63 votes
30 answers
408 views
Add a column with a default value to an existing table in SQL Server

How can I add a column with a default value to an existing table in SQL Server 2000 / SQL Server 2005?

avatar
Dorinda
0 1 0 9
asked 07 September, 2021
61 votes
30 answers
1.7K views
How do I UPDATE from a SELECT in SQL Server?

In SQL Server, it is possible to insert rows into a table with an INSERT.. SELECT statement: INSERT INTO Table

avatar
Jefferey
0 1 0 9
asked 07 September, 2021
60 votes
27 answers
2.9K views
What is the difference between "INNER JOIN" and "OUTER JOIN"?

Also how do LEFT JOIN, RIGHT JOIN and FULL JOIN fit in?

avatar
Louetta
0 1 0 9
asked 07 September, 2021