sql

MySQL - Set default value for field as a string concatenation function

Hi I have a table that looks a bit like this actors(forename, surname, stage_name); I want to update stage_name to have a default value of forename." ".surname So that insert into actors(forename, surname) values ('Stack', 'Overflow'); would produce the record 'Stack' 'Overflow' 'Stack Overflow' Is this possible? Thank...

mysql - embed count query within another query

In postgres I am fairly sure you can do something like this SELECT authors.stage_name, count(select id from books where books.author_id = authors.id) FROM authors, books; Essentially, in this example I would like to return a list of authors and how many books each has written.... in the same query. Is this possible? I susp...

MySql Query, Select greater than

I've got a table, called faq_questions with the following structure: id int not_null auto_increment, question varchar(255), sort_order int I'm attempting to build a query that given a sort order, selects the row with the next highest sort order. Example: id question sort_order 1 'This is question 1' 10 2 'Th...

SQL Query Advice - Most recent item

I have a table where I store customer sales (on periodicals, like newspaper) data. The product is stored by issue. Example custid prodid issue qty datesold 1 123 2 12 01052008 2 234 1 5 01022008 1 123 1 5 01012008 2 444 2 3 02052008 How can...

Oracle: How do I get the sequence number of the row just inserted?

How do I get the sequence number of the row just inserted? ...

mysql: joining tables + finding records with an AND style query, rather than OR

Note: Using MySQL 4.0, which means no subqueries (at present). I have 2 tables: A "user_details" table A "skills" table, which has the user_id and a "skill_id", which maps to a predefined set of skills defined elsewhere. The current query allows an admin to search for users by selecting skills, and the query works in an OR fashion, ...

What does the "@" symbol do in SQL?

I was browsing through the questions and noticed this: SELECT prodid, issue FROM Sales WHERE custid = @custid AND datesold = SELECT MAX(datesold) FROM Sales s WHERE s.prodid = Sales.prodid AND s.issue = Sales.issue AND s.custid = @custid I was wondering what the "@" does...

Techniques for data comparison between different schemas

Are there techniques for comparing the same data stored in different schemas? The situation is something like this. If I have a db with schema A and it stores data for a feature in say, 5 tables. Schema A -> Schema B is done during an upgrade process. During the upgrade process some transformation logic is applied and the data is stored ...

Virtual Private Server Hosting with Windows Server 2008 + MS SQL

I have seen this question pop-up on stackoverflow a few times but haven't found a good solution yet. I am looking for recommendations on Virtual Private Server Hosting featuring Windows Server 2008 plus MS SQL database capabilities. I have seen people suggest webhost4life.com, hostmysite.com and others but they do not offer windows ser...

SQL Query Advice - Get Previous Customer Order

Hi, I have the following table custid ordid qty datesold 1 A2 12 2008-01-05 2 A5 5 2008-01-02 1 A1 5 2008-01-01 2 A7 3 2007-02-05 What't the best way of getting the previous order for every customer? Thanks ...

Is there a standalone alternative to activerecord-like database schema migrations?

Hi! Is there any standalone alternative to activerecord-like migrations. Something like a script that is able to track current schema version and apply outstanding migrations. Basically, these migration files could be just a plain SQL files, something like: [timestamp]_create_users.sql reverse_[timestamp]_create_users.sql Language of...

Call an SQL script within an SQL script?

I am calling 4-5 SQL scripts from a single SQL script. I get errors like: Enter value for 1: MIG9 old 86: WHERE BLT.bill_id = '&1' new 86: WHERE BLT.bill_id = 'MIG9' SP2-0552: Bind variable "FINACLE" not declared.-----here i am calling FBA.sql file New Rows END OF FBE insert :0 PL/SQL procedure successf...

How do I pass the same input to all the sql files only once at the start?

hi I am calling 4-5 scripts from a file at once. But I need to give only one input to the file in the first sql that I am calling. That input will be the input for all the other sql files I have called after the first one. Is there any way to do that? please help. ...

adding oracle's timestamp to query results

Hi All, yesterday you had taught me to query record history within a time range here. What more I need is to add oracle's (historical) timestamp to the results as a column. Is it possible? Thanks in advance. ...

Import from Excel to MySQL database using SQuirrel

I have an Excel spreadsheet with a few thousand entries in it. I want to import the table into a MySQL 4 database (that's what I'm given). I am using SQuirrel for GUI access to the database, which is being hosted remotely. Is there a way to load the columns from the spreadsheet (which I can name according to the column names in the dat...

SQL User Defined Function Within Select

I have a user defined function in SQL called getBuisnessDays it takes @startdate and @enddate and returns the number of business days between the two dates. How can I call that function within my select? Here's what I'd like to do.. SELECT getBusinessDays(a.opendate,a.closedate) FROM account a WHERE ... ...

Problem with table JOIN in MySQL and aggregation

I have three tables. This query will write down the right answer (x-lines for btv.id_user with appropriate btv.cas and race.id_zavod SELECT `btv.id_user`, `btv.id_zavod`,`btv.cas` FROM `btv` JOIN `btu` ON `btv.id_user` = `btu.id_user` JOIN `race` ON 'btv.id_zavod' = `race.id_zavod` WHERE `race.type` = '8' AND `btv.id_user` = '607' Res...

What is the best default transaction isolation level for an ERP, if any?

Short background: We are just starting to migrate/reimplement an ERP system to Java with Hibernate, targeting a concurrent user count of 50-100 users using the system. We use MS SQL Server as database server, which is good enough for this loads. Now, the old system doesn't use any transactions at all and relies for critical parts (e.g. ...

SQL Server 2005 - Select top N plus "Other"

I have a table for which I want to select top the 5 rows by some column A. I also want to have a 6th row titled 'Other' which sums the values in column A for all but the top 5 rows. Is there an easy way to do this? I'm starting with: select top 5 columnB, columnA from someTable t order by columnA desc ...

Would you consider using an alternative to MS SQL Server Management Studio?

At work we recently upgraded from Microsoft SQL Server 7 to SQL 2005. The database engine is a lot more advanced, but the management studio is pretty awful in a number of ways. Most of our developers decided they preferred to stick with the old Query Analyzer tool, even though it had a lot of limitations. In my spare time, I decided t...