sql

Can you optimize this SQL query for me?

I'm running this query in 2 mysql_query calls. I would like to do the most performant thing and run it in one query. Can anyone optimize this for me: if(mysql_num_rows(eq("select * from player_data where uid = $uid")) == 0 ) eq("update player_data set uid = $uid, ...

SQL Concat Query

I have two tables like this: TABLE user( id CHAR(100) text TEXT ) TABLE post( postid CHAR(100) postedby CHAR(100) text TEXT FOREIGN KEY (postedby) references user ); I need a query that for each user concatenates the TEXT column of all posts of that user and put them in the text column of the user. the order is not ...

Entity Framework v4: Preventing Storage Model Overwrites by Update Model Wizard

In my Entity Framework v4 project, I have a table with two columns that are computed by the database (via triggers, etc.). In order to get EF to properly insert records into the table, I have to manually mark the columns as "Computed" in the EF Storage Model (the StoreGeneratedPattern attribute), which is not supported by the designer -...

Table permission problems when attempting to drop a table

Informix-SQL(SE) 4.10.DD6 (MS-DOS 6.22): I have a table created as: "pcuser".tablename. I attempted to drop this table with: DROP TABLE tablename; and received the following error message: 545: No write permission for table pcuser.tablename. Since my app is single-user and I'm not concerned with restricting privileges for any ta...

How do I remove duplicate results from my sql query

Thank you so much for helping! Ok, the portion of my query producing duplicate results is: Left Join CMS_ECH.dbo.hsplit hsplit on hsplit.row_date = ANDREWSTABLE.SegStart_Date and hsplit.split = ANDREWSTABLE.dispsplit and hsplit.starttime = ANDREWSTABLE.Interval ...

Need help performing a complex CoreData task

This would be hard with pure SQL and I'm REALLY not sure how to do it with CoreData. Is it possible to come up with a predicate or do I need to do this programmatically? Suppose (using the textbook example) I have a database of employees, some of whom are managers and some not. I want a list of managers who have an employee named "Joh...

How can I code this Interesting Condition Join SQL

In a nutshell here is what I want to happen: Complete the join, if the rows do not exist do the same join but using one different value to fill the null columns in each row. Here is my join: Left Join CMS_ECH.dbo.hsplit hsplit on hsplit.row_date = ANDREWSTABLE.SegStart_Date and hsplit.split=ANDREWSTABLE.dispsplit and hsplit.starttim...

Displaying multiple values from same name MySQL database field in Codeigniter & Dwoo

I am building a web application and have opted to use similar table and field names to Wordpress in my application. By that I mean I have a users table and a usermeta table similar to how Wordpress works. Forgive me for making this question so big, I opted to be as descriptive as possible in this question. The usermeta table has the fo...

How to treat a string as a month in SQL Server

In my database I have a table in which one of the columns is storing joining_months in string format like January, February, March....(and so on). Now I want to run a SQL query on this table to fetch those rows only in which joining month is before or after a user specified month. Something like: select * from table1 where joining_mon...

Large data store (nosql or not)

I have large amounts of scientific data that I need to store (150 TB+ starting data) and I want to know the best way to store the data (nosql or RDBMS etc...) Any tips...... James ...

Need help understanding Doctrine one to many

Referencing doctrine reference - one to many unidirectional class User { // ... /** * @ManyToMany(targetEntity="Phonenumber") * @JoinTable(name="users_phonenumbers", * joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")}, * inverseJoinColumns={@JoinColumn(name="phonenumber_id", referencedColumn...

Find Missing Pairs in SQL

Assume there's a relational database with 3 tables: Courses {name, id}, Students {name, id}, Student_Course {student_id, course_id} I want to write an SQL that gives me the student-course pairs that do NOT exist. If that is not feasible, at least it'd be good to know if there are missing pairs or not. Also, since this is a small part...

Entity framework model creation

When using the Entity Framework there are basically two ways to create your model. You either create the model in SQL server or in Visual Studio EF designer. Those are outlined below. Start with Database You first create the model in your SQL server DB then point EF to create the .edmx file for you. By using this approach you can use ...

Making sense out of many to many relationships in Doctrine

referencing doctrine reference - association mapping - many to many bidirectional /** @Entity */ class User { // ... /** * @ManyToMany(targetEntity="Group", inversedBy="users") * @JoinTable(name="users_groups", * joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")}, * inverseJoinColumns={@JoinC...

SQL LIKE with special characters

If I try to create a select with special (nordic) characters like: Select * from users where name like '%æ%' It just selects all users instead of those containing the letter 'æ'. Do I need to install some special drivers to the database, or is there something else I have missed? Update: I am using a SQL Server 2008 database, the col...

Relational Data: entity inheritance approaches. Best practice

There are several approaches how to store entities hierarchy in relation database For example there is person entity (20 basic attributes), student entity (the same as person but several new specific fields are present), employee (the same as person but some new fields are present) e.t.c. When you advice to use (and not to use) the fo...

How to write a stored procedure to return a count of events grouped by 'X' week blocks?

I have a table that records market interactions by employees with customers. Relevant fields would be customerid, date and customer type. I want to be able to get a count of interactions by 5 week blocks going back as far as the between dates that would be submitted by the user and discriminate by customer type a,b,c. I want to be able...

Unix time in SQL

Is it possible to get the current UNIX timestamp with sql? ...

How to select top x from with params?

I'm using Sql-Server 2005 I have Users table with userID and gender. I want to select top 1000 males(0) and top 1000 females(1) order by userID desc. If i create union only one result set is ordered by userID desc. What other way to do that? SELECT top 1000 * FROM Users where gender=0 union SELECT top 1000 * FROM Users where gender=1 ...

Recover data from a DB2 backup ( a diff of databases would be great!)

Time line: 1_ Made backup of database 2_ Deleted a row from table that deleted +100 others records in other tables since they where with the constrait ON DELETE CASCADE. 3_ Made backup of database 4_ Made a lot valid of updates/deletes/inserts. 5_ Need to recover the data lost in 2 I've seen the rollforward db2 command, but it's n...