sql

SQL query to get all the combinations of two columns

Hi All, Two days ago I was asked this question in an interview for Data Analyst position. Could some one please let me know the correct answer for this? Say there is a single table with three columns. 1st column with GeneId(primary key) 2nd column Flag1, 3rd column Flag2. Flag1 and Flag2 columns can have values of 0 or 1. How d...

Grand total of accounts SQL

I am a student this is homework... I have one table with four columns: Accounts(numbers), balances(money), and two for descriptions. I have to get a grand total of the balances... This VIEW shows the sums of the balance column but I need to total the sums, also. Any help pointing me in the right direction will be appreciated. CREATE V...

Error Code 1064 MySQL

I need to know what i am doing wrong right now in this. Can someone tell me how to fix it? mysql>host/"localhost"; mysql>port=3306; database=ml username=**** password=******** clientamount=30; I need to know how to fix the first line can anybody tell me? ...

Help with sql query

Have 2 table 1st {id_city,name } 2nd table {id_ctz,name,sname,age,id_city} need selected full information (name(city),name,sname,age) people with same name accending by age? Have tried: select city.name,citizen.name,age from citizen,city where city.id_city = citizen.id_city and citizen.name = '%s' order by age asc input vari...

Error "The primary key column of type 'DateTime' cannot be generated by the server."

I have a composite primary key (Int and DateTime) on one of my tables. When I try to add a new record using LINQ (with the DateTime field set to "AutoGeneratedValue = true", and getdate() as default value on the server), I get the following errors: The primary key column of type 'DateTime' cannot be generated by the server. Any ide...

How to update a counter for a resultset

Hi, i'm creating something similar to an advertising system. I would like to show, for example, 5 ads (5 record) from a given database table. So i execute something like SELECT * FROM mytable ORDER BY view_counter ASC LIMIT 5 ok, it works. But, how can contextualy update the "view_counter" (that is a counter with the number of sh...

Hey guys, can someone help me in this SQL Query...

This is a query based on the Northwind Database in MS SQL Server 2005. First I have to get the average of the UnitPrice from OrderDetails table, and group it by ProductID for that particular column alone and alias it as AveragePrice. Then I need to find the maximum(AveragePrice) which is nothing but the max of previous column, how can ...

query for substring formation

I want to take the 01 part of a string abcd_01 using SQL. What should be the query for this, where the length before the _ varies? That is, it may be abcde_01 or ab_01. Basically, I want part after the _. Thanks. ...

Need to add LF to thousands of MySQL MEDIUMTEXT fields

I need to add a \n or LF or ASCII(x'0A') or however you want to encode it to the end of several thousand MySQL MEDIUMTEXT fields. I tried update wp_posts set post_content = concat(post_content,ASCII(x'0A')); but nothing is modified in the field as far as I can see. I suspect this is a limitation of MEDIUMTEXT/LONGTEXT fields, but it wo...

Execute DDL from hibernate

I know that SchemaExport should be my friend. But I am using liquibase and want to execute the DDL - pure sql statements - generated from liquibase to recreate the database before every test method. Do you see problems with the following code? I wonder that this seems to be so complicated ... public static int executeScript(String sqlF...

Verifying query results

After you've written a complex query or stored procedure, how do you verify that the results are 100% accurate, and assure yourself that this will be the case for all input parameters? My personal approach is to test, test, and test all the way through development - checking that NULLs do not appear where I don't expect them to, that ro...

Return SCOPE IDENTITY

I'm trying to return the SCOPE Identity of the inserted record in my stored procedure @temp_id, but how can I bind it to a label e.g <asp:ControlParameter ControlID="ASPxLabel_RequestTemp" Name="temp" PropertyName="Text" Type="Int32" /> its not working Thanks ...

Why cannot I select from more than one table in Oracle?

Hi, I'm using Oracle 10g Express Edition 10.2 and I use it from a C# application with Oracle.DataAccess 2.111 assembly. I can select data from one table, but if I try to select data from several tables, the set is empty. select * from Table1 works well, but: select * from Table1, Table2 select * from Table1, Table2 where Table1.Id ...

split data in field to row using SQL2000

Dear all, Please help me to find a solution. I have data in table like ID Code 1 123,456,789,12 2 456,073 3 69,76,56 I need to list of code in row ID Code Ref 1 123,456,789,12 123 1 123,456,789,12 456 1 123,456,789,12 789 1 123,456,789,12 ...

How could I design this database scenario?

I am trying to create a "Task" schema in my database. One field is "blockedBy" which represents another Task that is blocking this current task. I am new to SQL Server and databases in general. How can I create the table properly? It seems like the only valid options are numbers or text. Should I just store the ID number of the other ...

Looking for SQL Optimization Interview Questions

I'm on a project where I was asked to take a quick peek at some reporting SQL (in a SQL Server 2K5 environment) and was surprised at what I found: 4 to 5 levels of subquerys, distinct clauses, unions, and NoLock hints (which were needed because the SQL was running so long it was blocking standard processing) - all in the same set!. Beca...

Database migration through php

I have a mysql database that I am trying to migrate into another database. THey have different schema's and I have written a php script for each table of the old database in order to populate its data in to the new one. The script works just fine but the problem is that it does not move all the data. for example if I have a table and all...

Mysql query with multiple ID columns and php

Hi guys. I have 2 joined tables, each one has a primary key column named id. SELECT t1.*, t2.* from t1 join t2 on t1.fk_id=t2.id When I run the query above, both id fields are selected (t1.id and t2.id). My question is, how can I select the correct ID while I am looping through the result set? If I select $result->id, I will get t...

Need help on this SQL...

Here is the question: +--------------+ Ships | +--------------+ Duke of north | ---------------+ Prince of Wales| ---------------+ Baltic | ---------------+ I need to replace all characters between the first and the last spaces (excluding these spaces) by symbols of an asterisk (*). The number of asterisks must be eq...

Parallelism in PL/SQL

hi how can i run one query in pl-sql- in parallel? i need all the flow... ...