sql

How can I turn a single row column into a scalar in SQL?

This is sort of what I want to do, but MySQL doesn't seem to accept it. SELECT Name, Content, Lft, Rht FROM Articles WHERE (Lft > (SELECT Lft FROM Articles WHERE idArticle = 1)) AND WHERE (Rht < (SELECT Rht FROM Articles WHERE idArticle = 1)); I'm implementing the modified preorder tree transversal algorithm, and I want t...

A query to determine if a column is computed

Possible Duplicate: Get List of Computed Columns in Database Table (SQL Server) In SQL Server 2008 is there a stored procedure I can run or view I can query which shows whether a column is a computed column? I've tried querying information_schema.columns but it doesn't seem to provide this information. ...

How can I use SUM() to sum my result array?

My current method to add the rows together is like so: $totalxp = $row['Attackxp'] + $row['Defencexp'] + $row['Strengthxp'] + $row['Hitpointsxp'] + $row['Rangedxp'] + $row['Prayerxp'] + $row['Magicxp'] + $row['Cookingxp'] + $row['Woodcuttingxp'] + $row['Fletchingxp'] + $row['Fishingxp'] + $row['Firemakingxp'] + $row['Craftingxp'] + $row...

transact-sql question

Hi, Assume there were 100 records in tableA and tableA contained a column named 'price'. How do I select the first-n record if where sum of price > a certain amount (e.g. 1000) without using cursor? thanks ...

SQL Server: Get table primary key using sql query.

I want to get a particular table's primary key using SQL query for SQL Server database. In MySQL I am using following query to get table primary key: SHOW KEYS FROM tablename WHERE Key_name = 'PRIMARY' What is equivalent of above query for SQL Server ?. If There is a query that will work for both MySQL and SQL Server then It will be...

query on %age share in sql

How do we calculate the percentage market share in sql ON MYSQL 5.1 version? I need to find the %age share of each manufacture.The market share is given by number of handsets. ...

PostgreSQL Query trimming results unnecessarily

Hello, I'm working on my first assignment using SQL on our class' PostgreSQL server. A sample database has the (partial here) schema: CREATE TABLE users ( id int PRIMARY KEY, userStatus varchar(100), userType varchar(100), userName varchar(100), email varchar(100), age int, street varchar(100), city varchar(100), sta...

geting a variable from public scope to connect database part 2

$hostname['application'] = '127.0.0.1'; $username['application'] = 'root'; $password['application'] = 'root'; $database['application'] = 'band'; $dbdriver['application'] = 'mysql'; class database { private $hostname; private $username; private $password; protected $database; private $dbdriver; function __constru...

Should I use sessions for "LOGINS" on my site?

I have a classifieds website, where anyone (no need for login currently) can post a classified. It is PHP based. The procedure for posting is currently like this: click on "New Classified" ---> fill in a form of all information and hit "View classified before publishing it" ---> the form submits to a "verify classifieds" page, where...

SQL Server table to be retrieved using ADO in VC++

I have a table with 2 columns, PatientID and TestNo. PatientID can be same for more than 1 records but the TestNo will be always distinct. I want to know the SQL statement which can fetch me the highest value in the TestNo field among all the records which has same PatientID basically max(TestNo) . I want to pass the specific PatientID ...

Parse tree for SQL statements - precisely for "SELECT" statement

hi, I am writing (hand written) recursive descent parser for SQL select statement in c++, i need to know whether the parse tree created by me is correct or not. I want to check but i didn't get a good sources for sql parse trees. My way of approach is - writing a function for each production and in that function the result is adding to ...

vBulletin - extract usernames from user table

Hi I need to extract a list of all usernames from the user table in vBulletin of persons who were registered up to a certain date. So for example, I need all members up until 1st Oct, but after that is not required. The 'joindate' field is expressed in seconds I think. Eg. 1116022743. How can I can extract usernames on this basis? che...

Sybase IQ - how to show stored procedure without wrapping text?

Hello. Using Sybase IQ v12.7. Executing sp_helptext ProcedureName shows the text of the stored procedure which is fine. However it wraps lines at 80 characters. The question is, how to show text text of a stored procedure without wrapping? In Sybase Central Java Edition there is a feature see the text of a stored procedure (Tranact-...

Sync large local DB with server DB (MySQL)

I need to weekly sync a large (3GB+ / 40+ tables) local MySQL database to a server database. The two databases are exactly the same. The local DB is constantly updated and every week or so the server DB need to be updated with the local data. You can call it 'mirrored DB' or 'master/master' but I'm not sure if this is correct. Right now...

what is the harm of using executeQuery instead of executeUpdate for deleting rows

In my code I am using String query= "delete all from myTable"; stmt.executeQuery(query); Ideally for DML executeUpdate should be used instead. However, executeQuery too works well. So, was curious to know what could be the harm of using executeQuery instead of executeUpdate? ...

sql 3NF Normalization

is this in 3NF ? create table movies( id numeric primary key not null default autoincrement, name varchar(50) not null, release-date Date, price numeric, rating numeric, length numeric, description varchar(1500) ); create table movies( id numeric primary key, name varchar(20) ); create table genre( name varc...

Association between two entries in SQL table

Hi all, Imagine you have a database table that stores a list of people. You want to establish a relationship between peoples, i.e., person I is friend with person J. I suppose in this case, one needs a second table to store people associations. This table would contain two fields (person1, person2) and each entry corresponds to a one-t...

Primary Key issues when Migrating "Legacy" SQLite Databases to use the Entity Framework

I have recently started work on a project that has already been running for several years. The application is written in c# using Windows Forms for the UI and SQLite for the database. The database is currently accessed using ADO.NET via the System.Data.SQLite namespace. From time-to-time clients have received application and database up...

SQL query for SQL compact 3.5 group by problem

SELECT BabyInformation.* , t1.* FROM BabyInformation LEFT JOIN (SELECT * FROM BabyData GROUP BY BabyID ORDER By Date DESC ) AS t1 ON BabyInformation.BabyID=t1.BabyID This is my query. I want to get the one most recent BabyData tuple based on Date. The BabyInformation should left join with babyD...

to calculate sum() two alias named columns - in sql

To calculate sum() of two temp column names declared in query - in SQL stud table has only two columns m1,m2. total and total1 is given as temp name. select m1, m2, SUM(m1) + SUM(m2) as Total, SUM(m1) + SUM(m2) as Total1 from stud group by m1, m2 How to calculate grandtotal as sum(total)+sum(total1) with the col...