sql

SQL: How could I turn this into one query?

UPDATE a SET CountOfAA=dt.CountOf FROM @MediaResurce a INNER JOIN (SELECT aa.Sku,ISNULL(COUNT(bb.sku),0) AS CountOf FROM @MediaResurce aa LEFT OUTER JOIN @MediaResurce_Pics bb ON aa.sku=bb.sku ...

How to check that at least one row complies to a condition (WHERE clause) in MySQL?

The task is to have a query returning 0 if no rows are going to be returned if the condition is applied and 1 if there are going to be more than 0 rows. Preferably this query should be faster than just querying the table with the condition and limiting the query with 1 row in result set. ...

#1222 - The used SELECT statements have a different number of columns

Why am i getting a #1222 - The used SELECT statements have a different number of columns ? i am trying to load wall posts from this users friends and his self. SELECT u.id AS pid, b2.id AS id, b2.message AS message, b2.date AS date FROM ( ( SELECT b.id AS id, b.pid AS pid, b.message AS message, b.date AS date FROM ...

Where can I practice SQL?

How can I practice SQL? ...

stored procedure returns nothing

This stored procedure doesn't work. I've checked the SQL and it returns the correct value when parsed directly to the DB. It's really strange! It just returns 0 rows. What could be wrong? ALTER PROCEDURE dbo.GetSaltOfUser ( @eMail nvarchar ) AS DECLARE @result nvarchar /* SET NOCOUNT ON */ BEGIN SELECT @result = salt FROM ...

Mysql WHERE problem

Hi, I need help for this problem. In MYSQL Table i have a field : Field : artist_list Values : 1,5,3,401 I need to find all records for artist uid 401 I do this SELECT uid FROM tbl WHERE artist_list IN ('401'); I have all record where artist_list fields values are '401' only, but if i have 11,401 this query do not match. An...

How could i optimize this query?

UPDATE a SET CountOfAA=dt.CountOf, CountOfBB=dt.CountOf FROM @MediaResurce a INNER JOIN (SELECT aa.Sku,ISNULL(COUNT(bb.sku),0) AS CountOf FROM @MediaResurce aa LEFT OUTER JOIN @MediaResurce_Pics bb ON aa.sku=bb.sku WHERE somec...

Get count of posts from a union mysql query?

SELECT u.id AS pid , b2.id AS id , b2.message AS MESSAGE, b2.uid AS uid, b2.date AS DATE FROM ( (SELECT b.id AS id , b.pid AS pid , b.message AS MESSAGE, b.uid AS uid, b.date AS DATE...

how to count model of car

Possible Duplicate: how to count of model of car here is the database for car ID CarRego Model Make ManufactureYear PersonID -------------------------------------------------------- 1 abc123 Van Toyota 2001 1 2 abc234 Ute Honda 2005 1 3 pio345 Hatchback Mitsubishi 1...

Recover unused space in SQL Table

We recently moved the value of a column from an existing table to a new table so that it could reside on a separate disk. The preexisting column still remains but has been set to null as some historical applications may still reference this column when writing data. The table now has 10GB unused space that we can not reclaim even after...

Challenging data modeling scenario

I have to create a model that stores gameplay controls for games on several platforms. I am having trouble finding the right approach. Controller buttons are different on different systems (Wii, Xbox 360, PS3 have their own specific controller buttons.) Some games are actually several games packaged as one; this means a single product ...

Problem with distributed Computing with mdf files

I am using SQL EXPRESS EDITION 2005 and Created mdf data file using vb.net 2008. now i want to use this datafile in lan. i modified connection string "Data Source=.\SQLEXPRESS;AttachDbFilename=\Server\Data\Data1.mdf;Integrated Security=True;User Instance=True;Connect Timeout=60" it is showing security info error i want to use single ...

How to model something if the desired information is the same as an already existing record

How to model something if the desired information is the same as an already existing record e.g. Address (Street, Country, Province, Zip) We need to capture an User who has a permanent address and an address for correspondence (i.e. 2 rows per user). There is a provision to say that the "address for correspondence" is the same as the "p...

error Unknown column in 'where clause' matlab using an array of strings

I want to read a column from a table of data base and for every row that I have read, read some rows from another table. the elements that I read from both tables are Strings, my code is: query1 = 'select col1 from MyDb.table1 order by col1'; [x1]= mysql(query1); for i=1:size(x1) my=char(x1(i,1)); query2=spri...

Is multiple named query file possible

I always see a single file being used for named query. I have never seen multiple file for queries, but can it be done? ...

Total no of votes related to a object.

Hello all, i want to count total no of votes of a object with condition(given below): Initially if user is voting up then total votes increased by +2 and after few time if same user is voting down on same object then total votes decreased by -4. Initially if user is voting down then then total votes decreased by -2 and afte few time ...

What is the correct way to form MySQL queries in python?

I am new to python, I come here from the land of PHP. I constructed a SQL query like this in python based on my PHP knowledge and I get warnings and errors cursor_.execute("update posts set comment_count = comment_count + "+str(cursor_.rowcount)+" where ID = " + str(postid)) # rowcount here is int What is the right way to form queries...

Report can't connect to SQL Server if Windows Authetication

Hello: I want to preview a report in a Delphi 7 program that connects to a SQL database. The database can use SQL or Windows Authentication. If SQL Authentication my program do: MyReportComponent.Connect.Server:=myServer; MyReportComponent.Connect.UserId:=myUserId; MyReportComponent.Connect.Password:=myPassword; MyReportComponent.Conn...

Is SqlConnection-exceptions cached? Im getting the same exception even though changes have been made in between.

Consider this code (Yes its ugly but it should also work): try { // Test the connection to a database that does not exist yet... using (SqlConnection c = new SqlConnection("Data Source=localhost;Initial Catalog=test;Integrated Security=True")) { c.Open(); } // Dispose calls Close() } catch { //... will fail w...

Multiple inserts and selects in one stored procedure

I want to create a procedure that will A) check to see if TicketNumberInput is in table Tix_number.TicketNumber. B) if it does exisist, update the record to set UID to @uid and Set the Claimdate to GetDate() AND ... C) INSERT A RECORD INTO ANOTHER TABLE (TRANSACTION LOG TABLE) If the record does exist, simply add a record to the tr...