sql

A question about complex SQL statement

Table A has columns ID and AName, Table B has columns BName and ID. B.ID is foreign key of A.ID. Write a SQL statement to show data like: print column AName and C which describe whether Table B has ID in Table A, if exists 1 or else 0. So if A is: 1 aaa 2 bbb B is: something,2 output is: aaa,0 bbb,1 ...

EF problem with entity re-ordering and uniqueness constraint

I am using Entity Framework and I've come to an interesting stumbling block. Let's say there is a db table "Item" with "sequence" column of type int (and others of course). Column "sequence" must be unique and it is used for (re)ordering of items. EF maps this table to "Item" class with "sequence" int property. Now let's say I want to s...

Help with SQL query in C#

I'm trying to rename the columns. The syntax should be the column name between double quotes incase of two words, like this: SELECT p_Name "Product Name" from items So I'm trying to do it in C# code like this: string sqlqry1 = "SELECT p_Name \"Prodcut Name\" from items"; But I get an error: Syntax error (missing operator) in query...

Problem with PHP & SQL Query

I have a problem in php code inserting values into database (I use PHPMyAdmin). My DATABASE has 3 tables: Member with this fields: MemberID, MemberName Room with this fields: RoomID, RoomName Join with this fields: MemberID, RoomID The idea is to join the member in the room. My query was mysql_query("INSERT INTO join (RoomID, Mem...

deploying vb.net app with database on server

I have an application that accesses a sql server 2008 database. The server and database is stored on my local harddrive and I would like to learn to scale this up to having multiple users in our office access the application which I will i deploy on a server. For now the database will stay on my pc until I am ready to put it on a dedicat...

SQL statement to split a table based on a join

I have a primary table for Articles that is linked by a join table Info to a table Tags that has only a small number of entries. I want to split the Articles table, by either deleting rows or creating a new table with only the entries I want, based on the absence of a link to a certain tag. There are a few million articles. How can I do ...

How to optimize my PageRank calculation?

In the book Programming Collective Intelligence I found the following function to compute the PageRank: def calculatepagerank(self,iterations=20): # clear out the current PageRank tables self.con.execute("drop table if exists pagerank") self.con.execute("create table pagerank(urlid primary key,score)") self.con.execute("...

SQL Inner Join : DB stuck

I postet this question a few days ago but I didn't explain exactly what I want. I ask the question better formulated again: To clarify my problem I added some new information: I got an MySQL DB with MyISAM tables. The two relevant tables are: * orders_products: orders_products_id, orders_id, product_id, product_name, product_price, pr...

Keeping DB Table sorted using multi-field formula (Microsoft SQL Server)

I have a JOB table, with two interesting columns: Creation Date Importance (high - 3, medium 2, low - 1). A JOB record's priority calculated like this: Priority = Importance * (time passed since creation) The problem is, every time I would like to pick 200 jobs with highest priority, and I don't want to resort the table. Is t...

How to reuse results with a schema for end of day stock-data

I am creating a database schema to be used for technical analysis like top-volume gainers, top-price gainers etc.I have checked answers to questions here, like the design question. Having taken the hint from boe100 's answer there I have a schema modeled pretty much on it, thusly: Symbol - char 6 //primary Date - dat...

Get records from a specific month using SQLite

How would I write a SQLite query to select all records from a specific month? My dates are stored as Unix timestamps. PHP code is allowed in your solution if it's required. SQLite2-compatible queries only, please. :) ...

MySQL Need help constructing query: join multiple tables into single row

Hello stackoverflowers, Forgive me if this question has been asked and answered, I've searched and found a few that look similar but I'm too much of a novice with SQL to adapt them to my needs. Also forgive me if I don't use the correct terminology, I know it can be annoying when someone asks a question and they don't even know enough t...

SQL & PHP - Which is faster mysql_num_rows() or 'select count()'?

I'm just wondering which method is the most effective if I'm literally just wanting to get the number of rows in a table. $res = mysql_query("SELECT count(*) as `number` FROM `table1`"); $count = mysql_fetch_result($res,0,'number'); or $res = mysql_query("SELECT `ID` FROM `table1`"); $count = mysql_num_rows($res); Anyone done any d...

SQLite3, "ALTER TABLE" and durability

I'd like to run some ALTER TABLE statements on a sqlite3 database. What happens if the user kills the process or the power is cut while the ALTER TABLE is running? Will the database be left in a corrupt intermediate state? ...

LPX-00607 for ora:contains in java but not sqlplus

Hi I am trying to doing some SQL queries out of Oracle 11g and am having issues using ora:contains. I am using Spring's JDBC implementation and my code generates the sql statement: select * from view_name where column_a = ? and column_b = ? and existsNode(xmltype(clob_column), 'record/name [ora:contains...

How and when to update a MySQL index?

I'm using this SQL query to create an index: $query = "CREATE INDEX id_index2 ON countries(geoname_id, name)"; How do I update the index when new entries are added? Should I run a PHP script with the update query in CRON and run it every night? Is this best practice for automated index updating? ...

Help to choose NoSQL database for project

There is a table: doc_id(integer)-value(integer) Approximate 100.000 doc_id and 27.000.000 rows. Majority query on this table - searching documents similar to current document: select 10 documents with maximum of (count common to current document value)/(count ov values in document). Nowadays we use PostgreSQL. Table weight ...

Is NULL not allowed is SQL delete statement (for Derby)?

Hello Does anyone know why the following query fails in Derby? delete from MyTable where ((null = null) or (col1 = null)) OR ((102 = null) or (col2 = 102))) I get the following error: Error: Syntax error: Encountered "null" at line 3, column 3. SQLState: 42X01 ErrorCode: -1 The sql is being generated in a java program based on SQL...

cryptic error message: Length of Bind host variable exceeds MaxLength

Hi, I've encountered a cryptic error message thrown by Sybase IQ server. com.sybase.jdbc2.jdbc.SybSQLException: ASA Error -1001019: Function not supported on varchars longer than 255 Length of Bind host variable exceeds MaxLength , -- (df_Heap.cxx 2145) at com.sybase.jdbc2.tds.Tds.processEed(Tds.java:2636) at com.sybase.j...

How to connect to SQL Server from another computer?

Hi, I want to connect from home using SQL Server 2005 to another PC. I had a look on the msd...but before connecting it says I should connect to another computer using the computer management and it didn't work out....I can only connect to computers from my workgroup? Thanks, Luisa ...