sql

Move SQL data from one table to another

Hi there, I was wondering if it is possible to move all rows of data from one table to another, that match a certain query? For example, I need to move all table rows from Table1 to Table2 where their username = 'X' and password = 'X', so that they will no longer appear in Table1. I'm using SQL Server 2008 Management Studio. Thank yo...

foreign key and primary key error

hi expert as per our last discussion regarding duplicate invoice no. and you have suggetsed code like: create table Invoice ( companyID int, invno varchar(50), primary key (companyID,Invno) ) worked fine. but another table is invcarat same has field like: companyID(int) invno(varchar) -------------------------...

Tricky query solution

Hello everyone, Does anyone have any idea on how can you create a product filtering query (or queries) that will emulate the results on this page? http://www.emag.ro/notebook%5Flaptop Explanation If you press HP as a brand, the page will show you all the HP products, and the rest of the available filters are gathered from this query ...

Mysql index configuration

Hello, I have a table with 450000 row full of news. The table schema is like this: CREATE TABLE IF NOT EXISTS `news` ( `id` int(11) NOT NULL auto_increment, `cat_id` int(11) NOT NULL, `title` tinytext NOT NULL, `content` text NOT NULL, `date` int(11) NOT NULL, `readcount` int(11) NOT NULL default '0', PRIMARY KEY (`id`), ...

Can't get unique values

I'm using my sql to get unique values from database My query looks as follows, but somehow I'm not able to get unique results SELECT DISTINCT(company_name), sp_id FROM Student_Training ORDER BY company_name sp_id is the primary key, and then company_name is the companies name that needs to be u...

SQL database (Firebird): problem with a foreign key

My SQL database (Firebird) has a table named tTransaction. It contains two columns, senderFK and receiverFK. There are three other tables, tBufferStock, tFacility and tOutsideLocation. A sender or a receiver can be either a buffer stock, our own facility or a location outside. My problem is that I don't know how to let senderFK or rece...

How to get server name through code if SQL Server (Standard Edition) is installed.

How to get server name through code if SQL Server (Standard Edition) is installed. We pass the server name while creating a connection string to connect SQL Server. Can we retrieve this value through code? string sqlConnectionString = string.Format( "user id={0};password={1};server={2};Trusted_Connection=no;database=TestDB; connection ...

ANSI joins versus "where clause" joins

Hello, I develop against Oracle databases. When I need to manually write (not use an ORM like hibernate), I put join statements in the where clause sections. for example (this is simplistic just to illustrate the style): Select * from customers c, invoices i, shipment_info si where c.customer_id = i.customer_id and i.amount > 99...

Should I break 1 table out to many if it will be hit often?

Right now I have a table for Photos. I expect this table to be hit a lot. Will I improve performance if I break it out into 3 tables if, for exmaple, I have 3 different types of photos? Or will this not improve performance? ...

SQL query to calculate part of visit duration from log table

Hello, I have a table which logs the userid, course, sessionid and requestdate each time a webpage is loaded. I want to calcuate the duration per userid for a given courseid. It is problematic to do this due to overlapping timespans. The data provided here should result in 10 minutes duration per user for course 1. I can't seem to get ...

mysql escaped string storage

Hello! Could somebody explain me how to store a escaped string in a column limited in size of a mysql table. I mean, if I have a column to which I define a size (let's say varchar(10)), if I insert "abcdefghij" the limit is reached, but if I insert "abcde'ghij" I exceed the limit since the escaped result of this last string is "abcde\'gh...

How to Store BLOB data in Sqlite Using Tcl

Hello: I have a Tcl TK application that has a Sqlite back-end. I pretty much understand the syntax for inserting, manipulating, and reading string data; however, I do not understand how to store pictures or files into Sqlite with Tcl. I do know I have to create a column that holds BLOB data in Sqlite. I just don't know what to do on ...

Converting nested Selects in WHERE .. OR .. to INNER JOINS

Hi How would I convert the following to use INNER JOIN rather than nested SELECT? SELECT [Name].[NameValueID], [Name].[NameTypeID], [Name].[NameID], [Name].[Value] FROM [Name] WHERE Name.NameTypeID IN ( SELECT NameTypeID FROM @tbNameType ) OR Name.NameID IN ( SELECT NameID FROM @tbName) ...

SQL Free Text And Like

If I use like '%fish%' the following is returned AQUARIAN GOLDFISH FLAKES but if I use Contains([Description],' "fish*" ' ) it isn't is there something I can do? Basically I want to return anything that has the word fish in it anywhere. ...

Peculiar case with SQL Server, indices and parameters

I have a table, let's call it History. The primary key (aka Clustered Index) is called HIST_ID. The table has some 2300 rows in the development DB. Now consider the following two queries: Query 1: declare @x int set @x = 14289 select * from History where hist_id=@x Query 2: declare @x int set @x = 14289 select * from History where...

MySQL - Not using Index

I'm trying to figure out what I might be doing wrong. This query doesn't seem to be using the index, as its taking way to long. When executing: Explain SELECT a, b, c, d FROM `table` WHERE d = 4013456 id select_type table type possible_keys key key_len ref rows Extra` 1 SIMPLE table ALL...

Can I have a postgres plpgsql function return variable-column records?

I want to create a postgres function that builds the set of columns it returns on-the-fly; in short, it should take in a list of keys, build one column per-key, and return a record consisting of whatever that set of columns was. Briefly, here's the code: CREATE OR REPLACE FUNCTION reports.get_activities_for_report() RETURNS int[] AS $F...

Preferred approach for producing ranked SQL results?

Hi. I need to build some searching logic that produces ranked results. A simple example would be querying a table with firstname, lastname and zip code columns. The required output would be a list a rows that match, in order of the 'degree' of match. I.e., the top results would be those that matched on all three columns, followed by tho...

Get SUM of two columns linked to same column in different table

Hi I have a table "Events" for users to add events with the following fields: EventID EventName EventSlot (--> slotID) EventSlotExtra (--> slotID) (optional) EventLimit And I have another table "Slots" SlotID (int) SlotTime (this is 9am-10am, 10am-11am, etc) I need to query both tables so I can get a total of people attendin...

Liquibase noob strikes again - Error on sqlFile tag.

Hi, Im using the sqlFile to include an sql script that creates tables using oracle specific commands (NOCACHE, NO PARALLEL, stuff like that). My master.xml file includes all sql scripts and executes them. However, when it detects a tag, it fails and prints this error message. C:\update.bat master.xml Migration Failed: cvc-complex-type....