sql

View or User Defined Function?

I have a scenario where I combine two tables into one (using UNION) and also JOIN data from some other tables. I can do this either with a VIEW or a UDF/User Defined Function. Considering that I have no view so far at all in my database, but quite a few UDF's for fulltext search and the like, I'm tempted to use a UDF for this scenari...

Make DataBase portable

I'm developing a local application with a DataBase in SQL Server 2008 and Visual Studio, C#, I created and connected to the Database in the application, but when I pass to work to another computer, copy the all solution files, the information that had been saved in it doesn't exist, actually the entire Database doesn't exist, so I ask: h...

Selecting counts of multiple items, grouped by date

I have the following two tables as a part of my order processing system: order(id, date) order_item(order_id, item_id, type) The type is an enum which denotes which table to look the order_item up in. I want to write a query that selects the number of different item types ordered on each day. So it should produce something like: Dat...

SQL, counting from 0 to 10

hi. it may sound stupid, but i want to know how (if possible) to count from 0 to 10 by a sql command. i mean i want a sql query which produces one column consisting of numbers from 0 to 10, like this: 0 1 2 3 4 5 6 7 8 9 10 i'm currently using MySQL 5.0 ...

Changing the value of a table field after it has already been inserted

I am working with a CMS system, and using a kind of smartform am inserting fields into a table. In these fields are the name of a product, quantity and cost. cost and product name are taken from a products table, while quantity is input manually. I understand this is not the best architecture, but I am limited with the system I am wor...

SQL Server Startup Paramenter

Dear Friends, I found the following value in my SQL server Startup paramenter what is the meaning of that: -T1118 Thanks in advance. ...

Difference between SQL Server 2008 vs SQL server 2008 native client ?

I want to know the wt is the exact difference between SQL Server 2008 vs SQL server native client ? ...

Text in front of variables inside a foreach loop

I have set up a small script to handle a page where I have three checkboxes. The HTML for the checkboxes looks like this: <input type="checkbox" value="Ex1" name="Check[]" />Ex1 <input type="checkbox" value="Ex2" name="Check[]" />Ex2 <input type="checkbox" value="Ex3" name="Check[]" />Ex3 And the PHP script for these: if($_POST['Che...

Find parent node?

There are two tables one with node names and another with connection details(child, parent) between the nodes find the node which has no parent i.e, root node. Using SQL query. ...

Select multiple tables when one table is empty in MySQL

I'm trying to do SELECT * FROM a, b However, it doesn't return anything if one of the tables is empty. How do I make it so it returns 'a' even if the other one is empty? ...

Search mySQL with PHP, using a WHERE wildcard or an IF statement?

I'm letting users search my database for data by city. My query looks like: $results = mysql_query("SELECT * FROM mydb WHERE City='".$city."' LIMIT 10"); I want a user to be able to search 'all cities', so I'd like to either remove the WHERE statement if $city=='all cities'; or use a wildcard for the WHERE statement that matches all ci...

Is there a table comparing SQL commands with R commands ?

Or a list of how to do in R things you do in SQL (or vise versa) ? Thanks, Tal ...

Adding new fields vs creating separate table

I am working on a project where there are several types of users (students and teachers). Currently to store the user's information, two tables are used. The users table stores the information that all users have in common. The teachers table stores information that only teachers have with a foreign key relating it to the users table. u...

Restricting the length of a double field in SQL

I don´t have a field as such, but I am making a new field which is the result dividing an existing field, i.e. cost/1.15 Is there a way to restrict the result of this calculation to two decimal places? ...

Simple to advanced SQL queries examples to practice MySQL query performance optimization

Hi, Looking for websites/books SQL queries from simple to advance (queries optimization and performanance etc.. ) questions and examples to exam for MySQL Job. Thanks ...

restarting auto incrementing

I have a table with an id field, set to auto increment. However, say I insert 10 records, and then empty the table, the first new record will be id number 11. Why is this, and is there a way to prevent it from happening? ...

What are "common" (needed/useful to know) SQL Database-operations ?

I am looking for a good list (cheat-sheet?) of SQL tasks/commands for Database operations (although probably all of them are for that). Stuff like: JOIN - merge two tables WHERE - subset tables And so on But also a bit more elaborate tasks. My motivation is that I want to know SQL a bit better, and I thought it would be fun to tak...

Preventing duplicates in an SQL query?

Is there an easy way when inserting a new record to make it fail if one of the fields is a duplicate of one of the other fields? I don´t want the field to be a primary key or anything like that... ...

MySQL Query Design for Latest Post per Forum

Hello, i have this 3 tables forums_forum +-----+--------+-------------+-------+-----+ | fid | name | description | index | cid | +-----+--------+-------------+-------+-----+ | 36 | gdghdf | hjghj | 54 | 5 | | 45 | yutuy | iuyi | 99 | 6 | +-----+--------+-------------+-------+-----+ forums_threads +----+--...

Set IF statements to write something or not, to a column in MySQL

Is there a way to set an IF statement in MySQL or PHP to write something to a column or not? What I want to do is completely skip a column so that "NULL" is written to it, in case there is no data to be submitted in the column. In case nothing is to be submitted to the database in one column, I want it to be NULL for that record obvious...