I understand the point of GROUP BY x. But how does GROUP BY x, y work, and what does it mean? Answer Group By X means put all those with the same value for X in the one group. Group By X, Y means put all those with the same values for both X and Y in the one group.
SQL server query to get the list of columns in a table along with Data types, NOT NULL, and PRIMARY KEY constraints
I need to write a query on SQL server to get the list of columns in a particular table, its associated data types (with length) and if they are not null. And I have managed to do this much. But now i also need to get, in the same table, against a column – TRUE if that column is a
practicing WHERE and HAVING in SQL
here is the schema: alt text http://img30.imageshack.us/img30/3324/123vk.jpg here is the question: Point out the battles in which at least three ships from the same country took part. here is my …
Does AdventureWorks db have tutorials / exercises? [closed]
I downloaded and installed AdventureWorks db for sql server 2008. Are there any exercises or tutorials for it? I’d like to to practice SQL select statements
How to debug PDO database queries?
Before moving to PDO, I created SQL queries in PHP by concatenating strings. If I got database syntax error, I could just echo the final SQL query string, try it myself on the database, and tweak it …
How can I reset an MySQL AutoIncrement using a MAX value from another table?
I know this won’t work. I tried it in various forms and failed all times. What is the simplest way to achieve the following result? This is great for automation projects. Answer Use a prepared statement:
SQL: difference between PARTITION BY and GROUP BY
I’ve been using GROUP BY for all types of aggregate queries over the years. Recently, I’ve been reverse-engineering some code that uses PARTITION BY to perform aggregations. In reading through all the documentation I can find about PARTITION BY, it sounds a lot like GROUP BY, maybe with a little extra functionality added in. Are they two versions of the
How can I know if an SQLexception was thrown because of foreign key violation?
I want to tell the user that a record was not deleted because it has child data, but how can I be sure that the exception was thrown because of a foreign key violation? I see that there a sqlexception …
Get SQL a Django model has (or would call) on .save()
How can you get the SQL for a Django model’s .save(), i.e. from django.db import models class MyM(models.Model): text = models.TextField() How can you get the SQL that would be created/used in …
How to find unused tables in SQL Server
Is there a way of finding out when the data was last entered into a table? I’m trying to find obsolete tables within my database and would like to know if there is a simple script(s) that I can run? Answer You could try check the results of querying the sys.dm_db_index_usage_stats Dynamic Management View like this: This will return things