sql

Do I need to install SQL Server 2008 SP1 on the management studio express?

Basic Question - I have installed SQL Server Express 2008 with integrated SP1. This is the database engine alone. I realise now that I also need the express studio in order to perform a few tasks. I have installed it, however I know that it was the original installer from before SP1 was released. I have tried it and it appears to work...

Does UNION ALL return an array?

I have a sql statement that is a union of several queries. "SELECT a, b, c, 'd' as type FROM x WHERE id = $id UNION ALL SELECT a, b, c, 'e' as type FROM y WHERE id = $id UNION ALL SELECT a, b, c, 'f' as type FROM z WHERE id = $id ORDER BY a DESC LIMIT 10"; I try to iterate through the results and get 'a' value for each row but can't...

Online SQL Login - Visual Basic 2008

Hey guys, I have here a simple question for those expertise out there (but please explain well, I'm very new). I made a visual basic 2008 application that allows you to login from a database. I followed this video: http://www.youtube.com/watch?v=p0dcPiLYrck But the problem is that I have to keep debugging my app if I make a new user. ...

How to write a query returning non-chosen records

I have written a psychological testing application, in which the user is presented with a list of words, and s/he has to choose ten words which very much describe himself, then choose words which partially describe himself, and words which do not describe himself. The application itself works fine, but I was interested in exploring the m...

IN clause with integers in sqlalchemy/psycopg2

Just a beginner with the python/postgres combo so forgive me if this is trivial. I'm executing a raw SQL query with sqlalchemy along the lines of: SELECT * FROM table WHERE pk_table_id IN () For the example below I tried self.ids as a tuple containing string or integers as well as an array containing string or integers. Either way i...

SQL Join Problem

I'm pretty new to SQL and please bare with me while I explain this as it is quite hard to explain. I have 3 tables: Trip Promotion Promotion Cost. 1 ---- M 1 --------- M Sample data include: TripID TripName Date XYZ123 Hawaii 09/06/09 YTU574 Japan 09/09/09 GHR752 US 11/07/09 PromotionID T...

How to use rawQuery() in android

Hi, I have a sql query like this String loadFav = "SELECT _id, title, name, favorite FROM table1 where favorite= 1 " + "UNION ALL" + "SELECT _id, title, name, favorite FROM table2 where favorite= 1" ; Cursor mCursor = mSQLiteDatabase.rawQuery(loadFav, null); I got an error when run this query. I...

Prohibit MySQL from using full table scan on a query

Is there any way I can prohibit MySQL from performing a full table scan when the result was not found using indexes? For example this query: SELECT * FROM a WHERE (X BETWEEN a.B AND a.C) ORDER BY a.B DESC LIMIT 1; Is only efficient if X satisfies the condition and there is at least 1 row returned, but if the condition cannot be sat...

MySql: Top 2 records from each ID

I need to get top 2 records of each id from table: SELECT distinct table1.userid AS `Foruser`, (Select table2.Firstname from table2 where table2.table2id = table1.userid ) as 'USERName', (Select table2.email from table2 where table2.table2id = table1.userid ) as 'USERMail', (Select table2.gender from...

Recordset returns the correct number of row but with all field empty

hi I have the same copy of access running in 3 cities right now. they work prefectly ok. they are 99% the same with one minor difference. Each of them has two views which use different odbc connection to different cities DB (all these db are SQL 2005). The views act as datasource for some two very simple queries. however, while i tried ...

Check table name to update data (sqlite)

I have two table like this table_CN (_id, name, phone, favorite, title) table_EN (_id, name, phone, favorite) Then I select _id value from two table SELECT _id, name, phone, favorite FROM table_CN where _id='15'UNION SELECT _id, name, phone, favorite FROM table_EN where _id='15' After that I don't know how to determine which table...

postgreSQL inner join

i have sql query select * from "Roles" Join "Users" On "Roles".Role="Users".RoleId it return error column Roles.role does not exist query select * from "Roles" Join "Users" On Roles.Role=Users.RoleId return error missing FROM-clause entry for table "roles" how can i solve this problem? i aways work with ms sql ...

substring in MySQL

I am trying to insert a string in MySQL table. But the following is not what I am looking for. select substring_index('3|5|6|asdf asd|6|0|NULL', '|', 1) as first, substring_index('3|5|6|asdf asd|6|0|NULL', '|', 2) as second, substring_index('3|5|6|asdf asd|6|0|NULL', '|', 3) as third, substring_index('3|5|6|asdf asd|6|0|NULL', '|', 4) a...

SQL Delete and Update

Hi, I start learning SQL and I have some problem. I have one database with 4 tables. All 4 tables have column ID. Something like this : Table name................Column #1..................Column #2 Table1.................... ID......................Data1.. Table2......................ID......................Data2.. Table3.......

data storage limitation issue

I face one problem, one column is i have taken as numeric(38,0) Data stored in this column is going out of range, means it is reach it's storage limitation. i have tried with also bigint , but facing same problem.i can not take it as varchar because i have to use in another calculation so at that time i must need to convert it from varc...

MySQL not using indexes

Hi, I just enabled the slow-log (+not using indexes) and I'm getting hundreds of entries for the same kind of query (only user changes) SELECT id , name FROM `all` WHERE id NOT IN(SELECT id FROM `picks` WHERE user=999) ORDER BY name ASC; EXPLAIN gives: +----+--------------------+-----...

LOAD DATA LOCAL, How do I skip the first line?

I'm trying to Load a CSV file into my MySQL database, But I would like to skip the first line. I fact It contains the name of my columns and no interesting data. Here is the query I'm using: LOAD DATA LOCAL INFILE '/myfile.csv' INTO TABLE tableName FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERM...

Use fewer columns on SQL query through Hibernate Projections on Entity with ManyToOne relation

I'm trying to build a smaller SQL, to avoid the "select * from A" that is being build by default for hibernate Criteria. If I use simple fields (no relation), through "Transformers", I have can manage to have this SQL: select description, weight from Dog; Hi, I have this Entity: @Entity public class Dog { Long id; String descr...

Select and merge rows in a table in SQL Stored procedure

Have a temp table with schema: ID | SeqNo | Name ID - Not unique SeqNo - Int (can be 1,2 or 3). Sort of ID+SeqNo as Primary key Name - Any text And sample data in the table like this 1 | 1 | RecordA 2 | 1 | RecordB 3 | 1 | RecordC 1 | 2 | RecordD 4 | 1 | RecordE 5 | 1 | RecordF 3 | 1 | RecordG Need to select from this ...

PHP Registration Form - SQL

Hey all, I want to make a Registration form from PHP to register their username and password into my SQL Database. Here is what I have: config.php: <?php $host['naam'] = 'localhost'; // my host $host['gebruikersnaam'] = 'root'; // my database username $host['wachtwoord'] = ''; // my database password $host['d...