sql

select 10 rows with lowest time difference in sql

I'm using sql-server 2005 Hi, i have Users table with userID and registrationDate. I want to select shortest period of time between two registrationDates when first date is x and other row is x+10 rows. I don't mind cursor because i will run this query once in a while. I will explain again, i need shortest period of time between 10 us...

SQL Server - Clustered index design for dictionary

Hi, Would like some advice from this. I got a table where I want to keep track of an object and a list of keys related to the object. Example: OBJECTID ITEMTYPE ITEMKEY -------- -------- ------- 1 1 THE 1 1 BROWN 1 2 APPLE 1 3 ORANGE 2 2 W...

Differentiating between two Values in a single Number column..

Hi, I have a table which has only one number field: [ value NUMBER(12.0) ] I would like to store these two types of non negative numbers. Type A : ( a list of non negative numbers ) Type B : ( another list of non negative numbers ) I have just this one table. Without making any DML changes, is it possible for me to store both types ...

Get latest comment records and the corresponding post slugs in Wordpress

I have the following query for getting the latest comments: global $wpdb; $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,30) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->po...

User content site wide search - PHP/ MySQL

For a user content website I am creating, it has lots of sub-sections: Movies, Jobs, People, Photos, Mail, etc. It's like a yahoo portal but very very detailed with information search, like I a niching as deep as possible per topic unlike any site out there. I have the site being developed in codeignitor php and mysql. Search can be glob...

Simple trigger in SQL Server 2008

Hi. Can anybody tell me how can I update a column of a record when it is inserted to the database. Here's the pseudocode that I want. if( mytable.OriginalId == null ) mytable.OriginalId = Scope_Identity(); ...

SQL - Order by column from two tables

I have two tables: messages (messages users posted), likes (many to many relationship between users and messages - it says that user1 likes message5). messages --------- id, id_user, message, created_at likes ----- id_user, id_message, created_at If I send message, it goes to the messages table. If I like somebody's message, a new re...

Null pointer execption

i am facing null pointer exception in hibernate: org.hibernate.dialect.function.CastFunction.render(CastFunction.java:11) hibernate code is: ("Select date_format(str_to_date(form.dobDate,'%Y%m%d'),'%M (%Y)') as Month"); ...

Codeigniter Insert Multiple Rows in SQL

Hi, I am fresh to Codeigniter. I have a form which looks something like this. <tr> <td><input type="text" name="Name[0]" value=""></td> <td><input type="text" name="Address[0]" value=""><br></td> <td><input type="text" name="Age[0]" value=""></td> <td><input type="text" name="Email[0]" value=""></td> </tr> <tr> <td><input type="t...

Which is more efficient : 2 single table queries or 1 join query

Say tableA has 1 row to be returned but will have 100 columns returned while tableB has 100 rows to be returned but only one column from each. TableB has a foreign key for table A. Will a left join of tableA to tableB return 100*100 cells of data while 2 separate queries return 100 + 100 cells of data or 50 times less data or is that a...

SQL server-declare local variable: "there is already an object named '' in the database"

hello, I wrote the following stored procedure, in which I use a local variable 'syncParam': declare @syncParam bit select isSync into syncParam from MyTable where id=@id if (@syncParam='True')... else ... return @syncParam When I executed this stored procedure at the first time it worked, but after that I get the following error:...

SQL: is it possible to combine an INSERT and SELECT statement into one

I want to add a row using SQLs INSERT statement. Is it possible that as part of this statement I can somehow get the value of the column userId which I don't update but is the AUTO_INCREMENT primary key. I need this value to update another table, however I can't follow the Insert statement immediately with a SELECT statement as there is ...

sql query to find nth highest salary from salary table

How can i find the Nth highest salary in the sql server ...

SQL Server 2008 DBCC Problems

We have a database Ms DBCC CHECKDB (MS) Or ALTER DATABASE MS SET SINGLE_USER DBCC CHECKDB(MS,REPAIR_ALLOW_DATA_LOSS) ALTER DATABASE MS SET MULTI_USER Error message Msg 0, Level 11, State 0, Line 0 A severe error occurred on the current command. The results, if any, should be discarded. Msg 0, Level 20, State 0, Line 0 A severe er...

MYSQL DB- How to transform NESTED SETS to XML?

Hi, I'd need a MySQL query to transform my nested sets structure into XML. (no PHP) The Problem is how to close all tags correct. My method of resolution: 1) Find leaves 2) Make a "TAG"-string (group_concat) and make it shorter with level This is running: A[01,16] B[02,03] C[...

SqlDataAdapter Output Variable Question C#

I do not clearly understand how to format the SqlDataAdapter for output variables when working with C# Error Message: Index (zero based) must be greater than or equal to zero and less than the size of the argument list. Code Example (Stored Procedure works fine) private DataTable updateOrdEodHold(DataTable tb, out string mn...

Listing tables in mysql database

Hello How do you list the names / fields of all the tables in a mysql database ? Any code examples would be helpful, Thanks! ...

SQL : Represent a subquery in relational algebra

How do I represent a subquery in relation algebra. Do I put the new select under the previous select condition. SELECT number FROM collection WHERE number = (SELECT anotherNumber FROM anotherStack); ...

Using Linq to SQL and dbml to create _and_ upgrade database?

Im using dbml (c# vs2010) to model my database and DataContext.CreateDatabase() to create it. Some time later I add a new property to one entity-type and now I want to upgrade the SQL-database to fit the new version of the dbml-schema. How do I accomplish this? Do I have to delete and re-create the database or upgrade it manually? Is ADO...

Table auto increment does not work when data entered in running mode

i have written code that takes data from text box and updates but as i have set in mdf file that ID will be auto incremented but this dose not happen.but if i enter data by right clicking "Show table data" in server explorer then there is auto increment here goes code public partial class Form1 : Form { System.Data.SqlClient.SqlConn...