sql

SQL IN equivalent in CAML

Is there "nice" way to create a CAML query for SharePoint that does something like this? SELECT * FROM table WHERE Id IN (3, 12, ...) Or am I stuck with a nightmare of nested <Or> nodes? ...

Executing Dynamic SQL in Oracle (PL/SQL) and Ensuring Security....

If I have a valid SQL string; is there anyway I can execute it in my PL/SQL - but guarantee that it is a SELECT statement only...without doing complex parsing to ensure it doesn't have any escape characters/nested commands or any of that jazz? EDIT: What I'm really trying to accomplish is a generic, built-in to my application, querying...

What is the fastest way to insert a large amount of records into a SQL Server DB?

I need to insert millions of records being read from disk into SQL server. I am parsing these from a file on one machine, in what is a single-threaded process. Ideally I would want it to perform well if the SQL server is local or remote. It has to be done programatically in C#. ...

Comparing rows from two tables and and ouputting the result

Hello guys I've been trying to compare two similar tables that have some different columns Table 1 has columns ID_A, X, Y, Z and Table 2 has columns ID_B, X, Y, Z If both values from columns X or Y or Z are = 1 the result of the query would output columns ID_A, ID_B, X, Y, Z I thought it would be an intersect statement in there, ...

SQL - Select first 10 rows only?

Hi, How do I select only the first 10 results of a query? I would like to display the first 10 results only from the following query: SELECT a.names, COUNT(b.post_title) AS num FROM wp_celebnames a JOIN wp_posts b ON INSTR(b.post_title, a.names) > 0 WHERE b.post_date > DATE_SUB(CURDATE(), INTERVAL 1 DAY) GROUP BY...

PHP, MySQL - would results-array shuffle be quicker than "select... order by rand()"?

I've been reading a lot about the disadvantages of using "order by rand" so I don't need update on that. I was thinking, since I only need a limited amount of rows retrieved from the db to be randomized, maybe I should do: $r = $db->query("select * from table limit 500"); for($i;$i<500;$i++) $arr[$i]=mysqli_fetch_assoc($r); shuffle($arr...

Query to get the duration and details from a table

Hi: I have a scenario and not quite sure how to query it. As a sample, I have following table structure and want to get the history of the action for bus: ID-----TIME---------BUSID----OPID----MOVING----STOPPED----PARKED----COUNT 1------10:10:10-----101------1101-----1---------0----------0---------15 2------10:10:11-----102------1102--...

Want an efficient approach to retrieving records from a database when the retrieval is weighted and balanced.

Im working on something incredibly unique..... a property listings website. ;) It displays a list of properties. For each property a teaser image and some caption data is displayed. If the teaser image and caption takes a site visitors interest, they can click on it and get a full property profile. All very standard. The customer wants...

SQL Server WHERE Clause using Temporary Columns

Hi all, I have the following query, which uses a CASE statement. Is there anyway to add into the where clause WHERE IsBusinessDayFinal = 0? without using a temporary table? thanks so much! SELECT ac.DateTimeValue, CASE WHEN pc.IsBusinessDay IS NOT NULL THEN pc.IsBusinessDay ELSE ac.IsBusinessDay END AS IsB...

Sqlite3 "chained" query

I need to create a configuration file from a data file that looks as follows: MAN1_TIME '01-JAN-2010 00:00:00.0000 UTC' MAN1_RX 123.45 MAN1_RY 123.45 MAN1_RZ 123.45 MAN1_NEXT 'MAN2' MAN2_TIME '01-MAR-2010 00:00:00.0000 UTC' MAN2_RX 123.45 [...] MAN2_NEXT 'MANX' [...] MANX_TIME [...] This file describes different "legs" of a trajectory...

Normalize columns names in ORACLE 11g

Hello, I need remove the quotes from the names of the columns in many tables in my schema. there is any way to automate this process?, any function in oracle or some tool that allows me to change the names of the columns removing the quotes. I am using oracle 11g. UPDATE I'm sorry, I had to rephrase my question. thanks in advance. ...

How might I improve the execution time of my join-heavy query?

I am joining multiple tables in a MySQL query, and the execution of this query is very slow. I badly need to improve the execution time! I did some optimization, but still it loads slowly. Any suggestions? ...

order by in sql after subtracting column values

hi! i've a sql table with 3 columns: id, start, end i've to select all(SELECT *) the results and arrange them descending from the (start-end) value.. can i do that in a single sql command? any help? ...

What does this SQL code (joining on the same view twice) do?

I'm working my way through this explanation of Common Table Expressions at MSDN and I came across the code reproduced below. Can anyone explain to me what it does and how it does it? I'm pretty sure I understand the concept of the view that is created in the first half. But the SELECT that joins on that view twice is confusing me. CREA...

Need a mysql query

I have a table named 'role' id | parent_id | name ---+-----------+-------------------- 1 | NULL | Machine 2 | 3 | Ram 3 | 4 | Cpu 4 | NULL | Computer 5 | NULL | Electronic Device I need a (mysql or postgress sql) query which will give the possible parents of a particular role. For example the p...

Storage of none default values

Hi, can some explain to me how the database design would look like for the following approach: let's say there are two tables 'toys' and 'wishlist'. Every wishlist has one toy, but 'toys' doesn't contain all the toys there are in the world. To prevent unhappy children lets add a row to toys called 'miscellaneous' so they can specify the ...

Easy way to escape sql strings?

In my code I have this everywhere command.Parameters.Add("@name", DbType.String).Value = name; Is there an easier way? I would love to do something like command.command.CommandTextFn("insert into tbl(key,val) values(?, ?);", key, value); and have it figure out if the key/value is a string or int. I wouldn't mind if I had to use {0}...

CodeIgniter - continue on SQL error?

Hi Basically I have a table with a couple of columns marked Unique. I have a script that dumps a bunch of values into the table with a command like this: $this->db->query("INSERT INTO `table` (`col1`, `col2`, `col3`) VALUES (`val1`, `val2`, `val3`)"); Every so often my script will try to insert a row which would violate the uniquenes...

SQL Table Parameters

Why table params aren't allowed in SQL Server? Is there any solution to this? Example: using (SqlCommand myCommand = new SqlCommand("SELECT * FROM @table WHERE USERNAME=@username AND PASSWORD=HASHBYTES('SHA1', @password)", myConnection)) { myCommand.Parameters.AddWithValue("@table", table); myCommand.Parameters.Add...

mySQL SELECT join, group by or something

hi There, I can't get on the right track with this, any help would be appreciated I have one table +---+----------+---------+-----------+ |id | match_id | team_id | player_id | +---+----------+---------+-----------+ | 1 | 9 | 10 | 5 | | 2 | 9 | 10 | 7 | | 3 | 9 | 10 | 9 | | 4...