sql

How to trace the sql queries that my windows app generates?

I want to do sql client-side tracing to see the scope of databases and queries that my local Windows application is generating. Everyone on the Web talks about server-side tracing but my app talks to at least five different servers, so that's pretty hard to do effectively. Any recommendations? ...

How to check if a list have any different value

Hello, I have a table like the following: (date1, date2, date3, date4, date5) and I want to check if ANY of these dates is different than any other. The trivial solution is: WHERE date1 <> date2 OR date1 <> date3 OR date1 <> date4 OR date1 <> date5 OR date2 <> date3 OR date2 <> date4 OR date2 <> date5 OR date3 <>...

MySQL ignores my index

I'm running the following query in MYSQL select distinct straight_join cu.entryid entryid, t0.tokpos starting_position, t3.tokpos ending_position, t0.idxsent idxsent, 'TOKENS_44_340' tablename from TOKENS_44_340 t0, constraints_appraisal cu, TOKENS_44_340 t1, TOKENS_44_340 t2, TOKENS_44_340 t3 where t0.toke...

PHP / SQL (MySQL) function optimization help required

I'm currently trying to optimize a "bottleneck" function that is called really ofen in an application. In the application in question, options can be selected. But some options can be restricted by other. For example, when option "A" is selected, it restricts the selection of option "B". These restriction links are saved to a table whi...

Match two keyword list columns against another column for matches

I am using .NET 4.0 & C# and SQL Server 2008. I have a table Products with a column called Keywords. I have another table Interests with 2 columns Accept and Reject. All 3 columns contains keywords separated by commas. I need to match: If Accept & Reject are empty, then there is a match If Accept has keywords, then there should be at l...

Mysql query with different searchs in same table

What I'd like to do is search in a table with two different values, it's hard to explain so I will just give an example. Table: people +----------------+ | id name | |----------------| | 1 Bob | | 2 Jack | | 3 Waly | | 4 Alex | ++++++++++++++++++ Table: animals +-------------------------------...

In MySQL, need to join two tables with one table having multiple references to the second

I have two tables, one is signups and contained in it are two fields, firstchoice, and secondchoice. Another is a schedule table, and it has things like a begin and end date, and a semesterid. firstchoice and secondchoice from the signups table both reference the semesterid from the schedule table. I am trying to create a page which d...

MySQL: Select occurences of a row, then combine results with another query

I am totally lost in how I should do this. I'm trying to display a top 100 most liked songs list. I have this part to find the most 100 liked songs: SELECT like_song_id, COUNT(like_song_id) AS occurances FROM likes GROUP BY like_song_id ORDER BY occurances DESC LIMIT 100; That works fine, I get a list of the top songs in the right or...

mysql: searching BETWEEN dates stored as varchar

i would like to select * from table where dates between (some_date and another_date) the problem is that the dates are stored as varchar! here are examples of dates that i have: 7/29/2010 9:53 AM 7/16/2010 7:57:39 AM please notice that some records have seconds and some do not i dont care about the time at all i just need the date ...

How to self JOIN recursively in SQL?

I have a table: Series ======== ID SeriesName ParentSeriesID A series can be a "root" series, (ParentSeriesID is 0 or null) or it can have a Parent. A series can also be several levels down, i.e. its Parent has a Parent, which has a Parent, etc. How can I query the table to get a Series by it's ID and ALL descendant Series' ? So...

How to fix this stored procedure problem.

Hi I have 2 tables. The following are just a stripped down version of these tables. TableA Id <pk> incrementing Name varchar(50) TableB TableAId <pk> non incrementing Name varchar(50) Now these tables have a relationship to each other. Scenario User 1 comes to my site and does some actions(in this case adds rows to Table A). So I...

mysql: get all characters before blank

i would like to get all the characters in a field before the blank if field1 = "chara ters" i want it to return chara what would this select statement look like? ...

Strange issue between sql server 2005 (32x) and sql server 2008 (64x) linked server

Hi, I have successfully created linked server between 2005 and 2008 version. We changed a table schema on 2008 and re ordered the table columns. We also did the same on 2005 server. If we query both table in their own database then schema looks fine however when I do SELECT * FROM and Select * from then it is showing me old schema ...

FluentNHibernate One-To-One using a ForeignKey constraint.

Ok I have 2 objects and a foreign key. The first object is. public class OutboundEmailMap : ClassMap<OutboundEmail> { public OutboundEmailMap() { Table("OutboundEmail"); Id(x => x.Id, "OutboundEmailId") .UnsavedValue(0) .GeneratedBy.Identity(); Map(x => x.OutboundEmailGuid...

What type of data structure should I use for mimicking a file-system?

The title might be worded strange, but it's probably because I don't even know if I'm asking the right question. So essentially what I'm trying to build is a "breadcrumbish" categoricalization type system (like a file directory) where each node has a parent (except for root) and each node can contain either data or another node. This w...

[hibernate] SELECT AVG("...") with Criteria API

Hello, I'm having difficulties with translating following SQL syntax into Criteria API: SELECT AVG(dbo.Member.Points) FROM dbo.Member WHERE dbo.Member.PaidMemberRegDate IS NOT NULL; I have a Member class with a Points property. I just want to get the average Points of all Members that have the property PaidMemberRegDate set to null. ...

How to get Torque Criteria to use table aliases

Hey, I'm trying to create a query where I reference a table twice. I know how to do this in sql. It looks like this: SELECT t1.* FROM Table1 t1 LEFT JOIN Table1 t2 ON t1.ID = t2.OwnerID WHERE t1.Column1='ok' AND (t1.OwnerID = 0 OR t2.Column1='ok'); This will return all the elements of the table that are "ok" and ...

Ordering FULLTEXT searches on relevance and other fields

I'm using FULLTEXT natural language search, and I notice that it automatically sorts my results by relevance. However, when I start to add things to ORDER, it seems to no longer sort by relevance. Is there a way to explicitly set the importance of relevance sorting? ...

IsNull() on bigint's min value?

Why does the following expression in SQL Server return -9223372036854775808 and not 123? I am calling this from a stored proc where I can't pass null parameters declare @t bigint; set @t = -9223372036854775808; --min value for bigint / long select ISNULL(@t, 123) ...

Populate data in sql table

Hi, I have a table with two columns id_test1 id_test2 1 Null 2 Null 3 Null 4 Null 5 Null How can I update or populate the id_test2 as below? id_test1 id_test2 1 256 2 214 3 147 4 987 5 ...