sql

django Queryset with year(date) = '2010'

Hi there, I'm trying to build this query select * from m_orders where year(order_date) = '2010' the field order_date is a DateTime field. I just don't want to use raw sql queries here. Is it even possible to use e.g. MySQL functions in django quersets? ...

MySQL query help: how to pivot this table?

Given a table like this: ============================================== | ID1 | ID2 | ID3 | Name | Value | ============================================== | 16 | 1 | 100 | item_name | Toys | | 16 | 2 | 101 | item_name | Computer | | 16 | 1 | 102 | item_price | 55 | | 16 | 2 | 103 | item_price ...

how to select comments for each row

I have events table which include so many cols besides Id PK and table Comments which includes text, eventId and Id PK . how can I select the event information and it's comments in one single sql statement, how to use it and how it should look like !? Note that EventId(Comments) = Id(events) ...

Multiple row SQL Where clause

This is probably a simple SQL statement, but it's been a while since I've done SQL and I'm having issues with it. I have this table design: ID PositionId Qty LeagueId 1 1 1 5 2 3 2 5 3 8 5 2 4 1 6 4 What I need to get are all...

How to find all records which are NOT in this array? (MySql)

I have an array which contains a bunch of ID:s... I can't figure out how to write a query for finding all records which are NOT inside this array, in mysql. SELECT * FROM main_table WHERE .......... Any ideas? Thanks ...

MySQL create time and update time timestamp

I am creating some tables where I want to store the time when a record was created and when it was last updated. I thought I could have two timestamp fields where one would have the value CURRENT_TIMESTAMP and the other would have CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP. But I guess I can't do this because you can have only 1 times...

Get DateTime from SQL database

I have a DateTime record in my table in a database and I write a query to get it from the database: string command2 = "select Last_Modified from Company_Data where Company_Name='" + DescriptionEntryForm.SelectedItem.ToString() + "'"; SqlCommand search_company2 = new SqlCommand(command2, con_string.con); SqlDataReader company_reader2 = s...

SQL Server 2008 tables name problem

hi, Could you tell me how to remove the database name from the table's name. Each time I create a table the database name is automatically prefixed to the name this is my table definition Create table Links ( Id Int IDEntity(1,1) , DisplayName Varchar(250) NOT NULL, Href Varchar(250) NOT NULL, Tooltip Varchar(550) NOT NULL, IsVisible...

Mysql::Error: Specified key was too long; max key length is 1000 bytes

script/generate acts_as_taggable_on_migration rake db:migrate causes Mysql::Error: Specified key was too long; max key length is 1000 bytes: CREATE INDEX `index_taggings_on_taggable_id_and_taggable_type_and_context` ON `taggings` (`taggable_id`, `taggable_type`, `context`) What should I do? Here is my database encoding: mysql> S...

Select the lastest N day data from table

Hi I have a table price date time 1.0 20100815 1 1.2 20100815 2 1.3 20100815 3 2 20100814 1 3.1 20100813 1 3.2 20100813 2 : : : Now I want to select the latest 3 days price with all the time, I use like this select price, date from allquotes where date in (select date from al...

SQL Joins query not acting as wanted.

I have the following tables: CREATE TABLE `attendance_event_attendance` ( `id` int(11) NOT NULL AUTO_INCREMENT, `talk_id` varchar(200) NOT NULL, `membersAttended_id` varchar(200) NOT NULL, PRIMARY KEY (`id`), KEY `attendance_event_attendance_9ace4e5a` (`talk_id`), KEY `attendance_event_attendance_3c0dadb7` (`membersAttended_id`) ) ENGI...

how to represent trees and their content in MySQL?

I need to be able to store something like this: where the green is a template type, the gray is a field container type, and the white is field. (That being, a field has a label and some text, both mediumtext for simplicity; and a field container can store other field containers or text, and a template is a top-level field.) Now, let's...

Conditional Columns - MySQL query

I need to display a particular column in my SQL result only if it is not null. If it is null, I don't want that column to appear at all in my result. Is there a way to express this condition in SQL? ...

SQL to LINQ Conversion in C#

Can anybody tell the equivalent LINQ syntax for this query in c#? SELECT Users.UserName, UserStatus.StatusTitle, UserStatus.StatusDetails FROM UserStatus INNER JOIN Users ON UserStatus.UserId = Users.UserID where Users.userid=3 OR users.userID in ( SELECT UserFriends.FriendId FROM Users INNER JOIN UserFriends ON Users.Use...

T-SQL optimizing performance of various stored procedures question.

Hello, so I have written several stored procedures that act on individual rows of data by taking in an ID number. I would like to keep several stored procedures that can call this stored procedure at different levels of my database scheme. For instance, when a row is inserted I call this stored procedure. When something else is modified ...

Getting Root & Leaf Nodes for a Given Id - How to?

Assume I have a table that has the following structure: ================= | Id | ParentId | ================= | 1 | 0 | | 2 | 1 | | 3 | 1 | | 4 | 2 | | 5 | 2 | | 6 | 3 | | 7 | 3 | ----------------- This results in a tree like this: 1 / \ 2 3 / \ / \ 4 5 6 7...

Query needed: Matching Keywords - Accepted and Blocked - SQL Server 2008/C#

I asked this question earlier, but I changed the table structure based on recommendations. So, here's the question with the new tables and some additional requirements. I have the following tables: Products ID BIGINT Name VARCHAR(64) Category1_ID INT Category2_ID INT Category3_ID INT Categories ID BIGINT Name VARCHAR(64) Product_Key...

sql for Oracle updation

My query: UPDATE I_USER SET END_DATE = (select ENDDAT FROM TEMP_USER WHERE USERNAME = 'ABC') where USER_NAME = 'ABC'; This is the code for updating one row with where condition.If i want to update all the records in I_USER with the ENDDATE as per the TEMP_USER ,WHAT SHOULD I DO..? ...

UPDATE statement in Oracle

We are building a client program where parameters for storage in a web server with Oracle backend are set in the .Net client program and uploaded as a dataset via webservice. In the webservice code, data is read from the dataset and added to UPDATE statements on the web server (Oracle backend). Because the server will run on the custom...

How do I improve full-text searching

Hello, I have a SQL Server 2008 database. This database has 2 tables: Manufacturer ------------ ID, Name nvarchar(256) Product ------- ID ManufacturerID Name nvarchar(256) My application has a search box. I do not know if the user is going to provide a manufacturer name or a product name. In addition, I'm trying to be a little bit g...