sql

What is the best way to fast insert SQL data and dependant rows?

Hi, I need to write some code to insert around 3 million rows of data. At the same time I need to insert the same number of companion rows. I.e. schema looks like this: Item - Id - Title Property - Id - FK_Item - Value My first attempt was something vaguely like this: BaseDataContext db = new BaseDataContext(); foreach (...

read/write unicode data in MySql

I am using MySql DB and want to be able to read & write unicode data values. For example, French/Greek/Hebrew values. My client program is C# (.NET framework 3.5). How do i configure my DB to allow unicode? and how do I use C# to read/write values as unicode from MySql? Upddate: 7 Sep. 09 OK, So my Schema, Table & columns are set to...

Validating SQL query with PHP

The validation seems to fail for some reason. By the validation, I mean the "if ($result)" -part. How can I correctly validate SQL-query? $dbconn = pg_connect("host=localhost port=5432 dbname=heoa user=heoa password=123"); $email = $_POST['login']['email']; $result = pg_query_params( $dbconn, 'SELECT user_id ...

php wordpress query

I had posted this earlier on Stack Overflow, but couldn't get a positive result. I thought I should do this again. <?php require_once 'news/wp-config.php'; $howMany = 0; $query ="SELECT `ID`, `post_title`,'post_category', `guid`,SUBSTRING_INDEX(`post_content`, ' ', 100) AS `post_excerpt` FROM $wpdb->posts WHERE `post_status`= \"publish\...

how to use a like with a join in sql?

I have 2 tables, say table A and table B and I want to perform a join, but the matching condition has to be where a column from A 'is like' a column from B meaning that anything can come before or after the column in B: for example: if the column in A is 'foo'. Then the join would match if column in B is either: 'fooblah', 'somethingfo...

JET SQL for Access 2003

Hello all, I have the following SQL statement: Select Choose(1,Orders.Employee, Orders.Customer) as Name1, Choose(2,Orders.Employee, Orders.Customer) as Name2, [Shipped Date] FROM Orders; However, the field "[Shipped Date]" has a space in it and hence why I have put square brackets around it. The problem is, in SQL view, it seems to...

In continue of questions "DB Schema for storing tagged records" -- how to select list of items with tags?

Good day! There are a lot of questions how to store tags in DB here on stackoverflow, I finally decide to use Toxi approach (items table, tags table and many-to-many intermediate table) http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html I want to display a list of 20-50 tagged items on a page each with list of it's tag...

Automatic decimal number formatting in SQL or PHP?

In my DB, most numeric values are of type DECIMAL(10,6). They are currency columns. Now, when I retrieve the numbers from mysql, I get something like this 34.123456 //I want these 0.987654 500.000000 //I do not want these 1.000000 Is it possible to have the numbers automatically show up as integers when they are and to maintain deci...

MYSQL: Retrieve latest unique records

I have a table that logs rows with some duplicate data. The column fields are as follows: id: primary key, auto inc. member_id: int index item_qt: int id, member_id, item_qt, timestamp 553, 107, 10, time 552, 107, 25, time 551, 122, 6, time 550, 122, 9, time 549, 107, 19, time I would like to do a few thing...

difference of date in sql and php

how can calculate (now) - (date in database) ...

What's the easiest way to expose a SQL interface to my application?

I'm working on an application which stores data in tables, similar to an RDBMS. I'm looking for a way to let my users query this data using SQL. Ideally, I'd like to do this without having to implement my own SQL parser, query optimizer, etc. So far, ripping parts out of something like Apache Derby is looking like the best option, but...

Can you use index in mysql using "col1 OR col2"?

I have a mysql query that gets a list of private messages where a user is either the sender, or receiver. SELECT users_user1.user_name AS pm_username_1, users_user1.user_avatar AS pm_username_1_avatar, users_user2.user_name AS pm_username_2, users_user2.user_avatar AS pm_username_2_avatar, pms.* FROM pm pms L...

How do you store an IP Address (v4 or v6) as an int in any database using php?

I need to store IP address in the most compact way possible, searching is not a concern. This also needs to be compatible on Windows, Linux, and Mac using any DB (MySQL, SQLite, Postgre, etc). Thanks to the ip2long() and long2ip() functions in PHP I can convert a IP4 address to a small int field rather than a varchar(15) or whatever. Th...

When I Insert Rows into a SQL Server 2005 Table will the order be preserved?

When I select a series of rows from a sql server 2005 table using an "order by" clause and then insert them into a different (and empty) sql server 2005 table can I count on the rows staying in the same order. The reason I am asking is that I want to manipulate the rows using ADO.net. I want the rows in a specific order to improve th...

Linq to SQL: Get top 10 most ordered products

I'm wanting to grab the 10 most ordered products. My tables look similar to this: ProductProductID | ProductName OrderedProductProductID | OrderID OrderOrderID | DateOrdered At the moment I've got the following: return (from product in db.Products from orderedProduct in db.OrderedProducts where orderedProduct.Product...

Better database table design

I need to store a series of configuration values in a database. A couple ways I thought of to store them are: a table with 2 colums(name,value) and a row for each pair, or a table with a column for each config parameter and 1 row? With the first I only need to add another row to add a config value, with the second I need to add a column...

SQL Select help - removing white space

Hello all, I'm running into a problem when trying to select records from my 2005 MS-SQL database (I'm still very new to SQL, but I learned and use the basic commands from w3schools already). In theory, all my manufacturer records should be unique. At least that is how I intended it to be when I did my first massive data dump into it. Un...

updating a table by joining multiple tables

I have the following query SELECT e.topicShortName, d.catalogFileID, e.topicID FROM catalog_topics a LEFT JOIN catalog_files_join b ON a.catalogID = b.foreignKey LEFT JOIN catalog_files_join c ON c.foreignKey = b.catalogFileID LEFT JOIN catalog_files d ON d.catalogFileID = b.catalogFileID LEFT JOIN catalog_lu_topics e ON a.topicID = e.t...

How can i introduce multiple conditions in LIKE operator

I want to write similar SQL below select * from tbl where col like ('ABC%','XYZ%','PQR%'); i know it can be done using OR. But i want to know is there any better solution. ...

How do I use AXSD in SQL Server?

In SQL Server you can use an XML datatype and map it to relational columns using an AXSD schema. Mapping between XML and relational storage By using an annotated schema (AXSD), the XML is decomposed into columns in one or more tables. This preserves fidelity of the data at the relational level. As a result, the hierarchi...