sql

track sales for week/month and find the best sellers

Lets say I have a website that sells widgets. I would like to do something similar to a tag cloud tracking best sellers. However, due to constantly aquiring and selling new widgets, I would like the sales to decay on a weekly time scale. I'm having problems puzzling out how store and manipulate this data and have it decay properly over ...

Why does WordPress prefix its column names with the table name?

I noticed that in a recent update WordPress decided to change all of its column names to include the table name prefix. WHY?! The wp_posts table now has a column called post_title, for example. It used to just be title. I don't understand the reason for this change. There must've been one, yes? I just don't understand what possible rea...

datagridview update

I have a datagridview whose source is a datatable. There are orders and food names columns. I insert new values into the this datagridview and delete from the table. when I select one row and delete it, selected color moves to the top, and if I want to delete one more order for same food, I have to reclick it each time. How can I solve t...

merging two tables w/ same structure

Trying to merge two tables, but I can't really get my head around it. The structure is the exact same for both tables. However, every query I've researched seems to write one table over the other. I'm guessing this has to do with the fact that both tables share the exact same id. As they share unique ids I'd like to have a new id assign...

SQL: how to compare date values within nvarchar datatypes

How can I build a query statement like this: select * from men where Tdate between 01/01/01 and 02/02/02 The Tdate column is of type nvarchar I am working with SQL Server Compact Edition (sqlCE) Thanks ...

Help me understand the logic of complex SQL queries in MySQL and relational algebra...

Hey, I'm working on a simple project to create tables and insert data into them, and finally execute some queries. Please note: I'm using MySQL command client. My schema is easy to implement; it's no problem. Emp(eid: integer, ename: string, age: integer, salary: real) Works(eid: integer, did: integer, pct_time: integer) ...

Doing a count MySQL query?

I have the following table: UID | ID | Type 1 | 1 | product 1 | 2 | product 1 | 3 | service 1 | 4 | product 1 | 5 | product 2 | 6 | service 1 | 7 | order 2 | 8 | invoice 2 | 9 | product I want to end up with: UID | product | service | invoice | order 1 | 4 | 1 | 0 | 1 2 | 1...

one to many queries

Alright, I've just finished normalizing a table. What I didn't really consider when I was doing it is that I now have a one to many relationship... being that my sql knowledge is very, very limited I'm not really sure how to approach this. I tried grouping by the foreign key, but it only returns the last matching result and I want to re...

Database design for general web form

I want to build a back end of a general web form which contains questions which the user can answer. There are multiple types of questions. "Normal" text question: the question is answered via a simple text field. Example: General personal info, like the name. Textarea question: the same, but with more space to write the answer. Exampl...

build oracle sql query dynamically from java application

How do I build oracle pl/sql query dynamically from a java application? The user will be presented with a bunch of columns that are present in different tables in the database. The user can select any set of column and the application should build the complete select query using only the tables that contain the selected columns. For exam...

MySQL - Using UNION with LIMIT

i noticed that (SELECT title, relavency, 'search1' as source FROM search1 ORDER BY relavency DESC LIMIT 10) UNION (SELECT title, relavency, 'search2' as source FROM search2 ORDER BY relavency DESC LIMIT 10) ORDER BY relavency DESC LIMIT 10 the last LIMIT 10 does not work. why? the error was "Error code 1064: ... to use near 'LIM...

SQL guaranteed start/end index?

I (will) have hundreds of thousand of records where i insert once, never update with many rows holding the same previousId. Can i guaranteed a start/end index? where i insert X number of rows in table_c with a transaction and write the start and end (or start and length or end and length) into table_b instead of having each row hold tabl...

How is Database Migration done?

i remember in my previous job, i needed to do data migration. in that case, i needed to migrate to a new system, i was to develop, so it has a different table schema. i think 1st, i should know: in general, how is data migrated (with the same schema) to a different DB engine. eg. MySQL -> MSSQL. in my case, my destination DB was MySQL ...

SQL Three Table Join and sort

So, I have countries, regions and groups. countries |cid|name| regions |rid|name|cid| groups |gid|name|phone|time|rid| So how can I select each group with its country and region in order: eg. |cname|rname|gname|phone|time| |Australia|nsw|test|1111|whatever| |Australia|nsw|test2|110|whatever| |Australia|vic|test3|100|whatever| |Engla...

SQL Server connection count issue

Hello everyone, I am using SQL Server 2008 Enterprise + .Net 3.5 + C# + ADO.Net. I am using the following SQL statement to monitor connection number, is it correct? If yes, my confusion is, one connection from ADO.Net client maps to only one connection in the following statement? Or one ADO.Net connection could maps to multiple connecti...

SQL query is only retrieving first record.

Hi, I have a query which is designed to retireve the "name" field for all records in my "tiles" table but when I use print_r on the result all I get is the first record in the database. Below is the code that I have used. $query = mysql_query("SELECT name FROM tiles"); $tiles = mysql_fetch_array($query); I really cant see what I have ...

How can I get the actual CURRENT_USER for a dbo in SQL 2005?

I've got a stored procedure which runs this to create a new ticket number: INSERT INTO [Test_DB42].[dbo].[TicketNumber] ([On], [By]) VALUES (CURRENT_TIMESTAMP, CURRENT_USER) When I run with a user with db_datareader and execute permissions, I get the Active Directory samAccountName value which is what I want - this user gets a...

How to get a data's from one database to other database?

Using SQL 2000, SQL 2005 Old Database Name is – Sysdatabase New Database Name is - Dual_Proone, Dual_Protwo In the above two database table name and column name are different, but values are same. For Example Sysdatabase (Database Name) Person (Table Name) Column Names and values are ID Date 001 23-02-2009 002 24-02-2009 So o...

why can not add this foreign key?

I have this schema: CREATE TABLE `lotto`.`combinaciones` ( `indice` mediumint(8) unsigned NOT NULL, `binario` int(10) unsigned NOT NULL, PRIMARY KEY USING BTREE (`indice`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 CREATE TABLE `lotto`.`sorteo` ( `numeroSorteo` int(11) NOT NULL, `fechaSorteo` date NOT NULL, `precioCarton` doub...

How triggers will work?

Using SQL Server 2000 I make a trigger in new database CREATE TRIGGER [CARDEVENTSAVING] ON [dbo].[T_CARDEVENT] AFTER INSERT AS DECLARE @EDATE VARCHAR(50) DECLARE @ETIME VARCHAR(50) DECLARE @EDOOR NVARCHAR(50) DECLARE @EFLOOR NVARCHAR(50) DECLARE @EMPID NVARCHAR(50) DECLARE @TAG NVARCHAR(50) DECLARE @ENAME NVARCHAR(50) DECLARE @ELNA...