sql

MySQL conditional statement

Alright, so I have a query that looks like this: SELECT `orders`.*, GROUP_CONCAT( CONCAT( `menu_items`.`name`, ' ($', FORMAT(`menu_items`.`price`,2), ')' ) SEPARATOR '<br>' ) as `items`, SUM(`menu_items`.`price`) as `additional`, `children`.`first_name...

Is there a LINQ library for C++?

Are there any Platform agnostic (not CLI) movements to get LINQ going for C++ in some fashion? I mean a great part of server frameworks around the world run on flavors of UNIX and having access to LINQ for C++ on UNIX would probably make lots of people happy! ...

In SQL, how can you "group by" in ranges?

Suppose I have a table with a numeric column (lets call it "score"). I'd like to generate a table of counts, that shows how many times scores appeared in each range. For example: score range | number of occurrences ------------------------------------- 0-9 | 11 10-19 | 14 20-29 | 3 ......

SQL Query Where Field DOES NOT Contain $x

I want to find an SQL query to find rows where field1 does not contain $x. How can I do this? ...

DB sketcher for MacOS?

I've been trying to find a free database creator for mac os, and i'm not being able to find any. Anyone know of a free one i could download? EDIT: I need that the application generate the sql (mysql in this case) also :) ty ...

LINQ to SQL multiple DataContext-s

I'm trying to figure the best strategy about how to organize DataContexts. The typical DB we work has between 50 and 100 tables usually in third-normal form and with many relations between them. I think we have two options: Put all tables in a single context. This will ensure that anything we do will be committed in the correct order i...

How can I create a copy of an Oracle table without copying the data?

I know the statement: create table xyz_new as select * from xyz; Which copies the structure and the data, but what if I just want the structure? ...

INSERT vs INSERT INTO

I have been working with TSQL in MSSQL for some time now and somehow whenever I have to insert data into a table I tend to use syntax INSERT INTO myTable <something here> I understand that keyword INTO is optional here and I do not have to use it but somehow it grew into habit in my case. My question is: Are there any implications...

Getting a sqlexception on successful insert, VB.NET

I'm trying to do a very simple INSERT using VB.NET. For some reason I'm getting a SqlException on every insert though. The data is inserted, but still get the following: Violation of PRIMARY KEY constraint 'PK_User'. Cannot insert duplicate key in object 'dbo.Employee'. The statement has been terminated When I check in SQL Managemen...

SQL - Multiple Values comma separated when using GROUP BY

I have data that looks like CUSTOMER, CUSTOMER_ID, PRODUCT ABC INC 1 XYX ABC INC 1 ZZZ DEF CO 2 XYX DEF CO 2 ZZZ DEF CO 2 WWW GHI LLC 3 ZYX I'd like to write a query that'd make the data look like this: CUSTOMER, CUSTOMER_ID, PRODUCTS ABC INC ...

How to use Explain Plan to optimize queries?

I have been tasked to optimize some sql queries at work. Everything I have found points to using Explain Plan to identify problem areas. The problem I can not find out exactly what explain plan is telling me. You get Cost, Cardinality, and bytes. What do this indicate, and how should I be using this as a guide. Are low numbers better? ...

Is there a 'greatest' function in db2?

I found in MYSQL and apparently other database engines that there is a "greatest" function that can be used like: greatest(1, 2, 3, 4), and it would return 4. I need this, but I am using IBM's DB2. Does anybody know of such an equivalent function, even if it only accepts 2 parameters? I found somewhere that MAX should do it, but it do...

Aggregate adjacent only records with T-SQL

Hi, I have (simplified for the example) a table with the following data Row Start Finish ID Amount --- --------- ---------- -- ------ 1 2008-10-01 2008-10-02 01 10 2 2008-10-02 2008-10-03 02 20 3 2008-10-03 2008-10-04 01 38 4 2008-10-04 2008-10-05 01 23 5 2008-10-05 2008-10-06...

Is it possible to change SQL user-defined data type?

I have a bunch of tables using user-defined data type for PK column. Is it possible to change this type Using SQL Server 2005? ...

Rows in their own columns depending on their value

I have a select query that currently produces the following results: Description   Code   Price Product 1       A       5 Product 1       B       4 Product 1       C       2 Using the following query: SELECT DISTINCT np.Description, p.promotionalCode, p.Price FROM Price AS p INNER JOIN ...

Finding the difference in rows in query using sqlite

After a few hours of searching, I'm not getting anything that works with Sqlite. It's driving me nuts. I have an sqlite table that contains prices for various products. It's a snapshot table, so it contains the prices on 5 minute intervals. I would like to write a query that would return the difference in price from one row to the next ...

Foreign keys in MySQL?

I have been slowly learning SQL the last few weeks. I've picked up all of the relational algebra and the basics of how relational databases work. What I'm trying to do now is learn how it's implemented. A stumbling block I've come across in this, is foreign keys in MySQL. I can't seem to find much about the other than that they exist in...

Help write a query: Confusion over order of operations of GROUP BY and ORDER BY

I have a table named Info of this schema: int objectId; int time; int x, y; There is a lot of redundant data in the system - that is, objectId is not UNIQUE. For each objectId there can be multiple entries of time, x, y. I want to retrieve a list of the latest position of each object. I started out with this query: SELECT * FROM Inf...

Generate Linq DataContext

Hello, Does anyone know if an API exists for Linq's DataContext generator? I reflected SqlMetal.exe, but every class was marked internal. I would like to generate a datacontext .cs like sqlmetal, but from my own assembly. Thanks! James ...

SQL - Table Design - DateCreated and DateUpdated columns

For my application there are several entity classes, User, Customer, Post, and so on I'm about to design the database and I want to store the date when the entities were created and updated. This is where it gets tricky. Sure one option is to add created_timestamp and update_timestamp columns for each of the entity tables but that isn't...