Hello, I have an sql select query that has a group by.
I want to count all the records after the group by statement.
Is there a way for this directly from sql?
For example, having a table with users I want to select the different towns and the total number of users
select town, count(*) from user
group by town
I want to have a colum...
Hi,
I need to provide 4 MySQL stored procedures for each table in a database. They are for get, update, insert and delete.
"Get", "delete" and "insert" are straightforward. The problem is "update", because I don't know which parameters will be set and which ones not. Some parameters could be set to NULL, and other simply won't change s...
This is an oddball question I figure.
Can I get NHibernate to ask SQL to sort data by CreatedDate by default unless I set an OrderBy in my HQL or Criteria? I'm interested in knowing whether this sort can be accomplished at the DB level to avoid bringing in LINQ.
The reason is that I use GUIDs for Ids and when I do something like this:
...
The following statements give the same result (one is using "on", and the other using "where"):
mysql> select * from gifts INNER JOIN sentGifts ON gifts.giftID = sentGifts.giftID;
mysql> select * from gifts INNER JOIN sentGifts WHERE gifts.giftID = sentGifts.giftID;
I can only see in a case of a Left Outer Join finding the "unmatched"...
Hi,
I’m having some difficulties with two queries. I can get some of the information but my problem lies in the some special conditions I just can’t seem to get right in the SQL statement.
The first query is in natural language defined:
I’m going to find all the candidates who has acquired two qualifications but during the same time p...
I'd like to know what my best option would be to import data from an excel file on a weekly or monthly basis. At first, I thought I would use SSIS, but after much struggle with seemingly simple tasks, I'm starting to rethink my plan. Would it be better/easier to just write the SQL by hand or use the services of an SSIS package? The ba...
SELECT
items.item_id, items.category_id, items.title, items.description, items.quality,
items.type, items.status, items.price, items.posted, items.modified,
zip_code.state_prefix, zip_code.city, books.isbn13, books.isbn10, books.authors,
books.publisher
FROM
(
(
items
LEFT JOIN bookitems ON items.item_id = bookitems.ite...
Here is the scenario:
I have a table that records the user_id, the module_id, and the date/time the module was viewed.
eg.
Table: Log
------------------------------
User_ID Module_ID Date
------------------------------
1 red 2001-01-01
1 green 2001-01-02
1 blue 2001-01-03
2 green 20...
When looking at the actual execution plan for a query in SQL Server Management Studio (SSMS), how do I determine what an expression such as Expr1052 represents?
When I identify the costly parts of the query and look at the properties of that operation, there are often references only to these Expressions, or scalar operators. I want to...
I'm trying to make a query that looks at a single table to see if a student is in a team called CMHT and in a medic team - if they are I don't want to see the result.
I only want see the record if they're only in CMHT or medic, not both.
Would the right direction be using sub query to filter it out? I've done a search on NOT IN but h...
I'm wondering how SQL Server orders data that is returned from a query and the Id columns of the respective tables are all of type uniqueidentifier.
I'm using NHibernate GuidComb when creating all of the GUIDs and do things like:
Sheet sheet = sheetRepository.Get(_SheetGuid_); // has many lines items
IList<SheetLineItem> lineItems = sh...
a) If a query/subquery doesn’t find any matching rows, then it either
returns NULL or no value at all, thus not even a NULL value. Based on
what criteria does a query/subquery return a NULL and when
doesn’t it return any results, not even a NULL value?
b) I assume a scalar subquery will always return NULL, when no
matching rows are foun...
I have a Silverlight app that calls a WCF service, the service calls some stored procedures in an SQL db using Visual Studio 2008's Link to SQL class and returns the information to whatever called it.
I have set up the compiled project (website with embedded app and the WCF service) on an remote IIS 7 server. I recompiled my local copy ...
I got the following trigger on my sql server 2008 database
CREATE TRIGGER tr_check_stoelen
ON Passenger
AFTER INSERT, UPDATE
AS
BEGIN
IF EXISTS(
SELECT 1
FROM Passenger p
INNER JOIN Inserted i on i.flight= p.flight
WHERE p.flight= i.flightAND p.seat= i.seat
...
I need to start a SSIS package via a stored procedure. I chose to use 'exec dtexec' instead of starting a job to launch the package, so I can have the ability to set variable in the package. My problem is that I need the package to run asynchronously so that the stored procedure will return instead of it hanging or timing out.
What is ...
I can already see that I'm not going to enjoy the experience, but I have to do some sql cleanup on this 1000 file asp classic web-app without any prior knowledge of asp, and before I get to hacking away at it I'd like to be aware of any major gotchas to watch out for while coding in asp classic/sql parameter preparing/making asp whitespa...
Snippet of original table:
CREATE TABLE [dbo].[Batch](
[CustomerDepositMade] [money] NOT NULL
CONSTRAINT [DF_Batch_CustomerDepositMade] DEFAULT (0)
Snippet of copied table:
CREATE TABLE [dbo].[Batch](
[CustomerDepositMade] [money] NOT NULL,
Code for copy database:
Server server = new Server(SourceSQLServ...
I am lost in MySQL documentation. I have a table with votes - it has these columns
id
song_id
user_id
created
I cannot find the query which will process the information and output the 10 most voted songs in a given time period. What is it?
...
Hello, guys!
I have a problem and I dont know what is better solution.
Okay, I have 2 tables: posts(id, title), posts_tags(post_id, tag_id).
I have next task: must select posts with tags ids for example 4, 10 and 11.
Not exactly, post could have any other tags at the same time.
So, how I could do it more optimized? Creating temporary tab...
So i have a SQL table setup as such
CREATE TABLE IF NOT EXISTS `points` (
`id` int(11) NOT NULL auto_increment,
`lat` float(10,6) NOT NULL,
`lng` float(10,6) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
And im inserting stuff like
INSERT INTO `points` (`lat`, `lng`) VALUES ('89.123456','-12.123456');
Gives me a row with l...