select

How to compare values from different tables with a single query on Linq-to-SQL?

The code, with two Linq-to-SQL queries, that I am trying to optimize is below: var maxAInstant = ( from a in db.As select a.Instant ) .Max(); var maxBInstant = ( from b in db.Bs select b.instant ) ...

Sql table unresponsive when selecting or counting all rows

We have a table in a database that has 35 rows, according to exec sp_spaceused Department. I am able to run SELECT TOP 1 * FROM Department, and get a result, but when I run SELECT COUNT(*) FROM Department, it runs longer than 2 minutes (I then cancelled it and did not wait for a result, since I expect this to be a simple and fast...

How do I handle date objects in ruby on rails forms?

I am using a rails helper that creates 3 select lists for the purpose of letting a user select a date. If I assign the helper a name, it sets all 3 select lists to have that name, and then only the last one goes through (it overwrites the previous). What I need to know is: What is the best way to take a set of 3 select lists (day, mont...

Add row to query result using select

Hey guys, is it possible to extend query results with literals like this? Select name from users union select name from ('JASON'); or Select age, name from users union select age, name from (25,'Betty'); so it returns all the names in the table plus 'JASON', or (25,'Betty'). Thanks! ...

PostgreSQL functions select*

How can I use select * from some_table in a function in postgres? ...

How do I select an element in jQuery by using a variable for the ID?

For example, the following selects a division with id="2": row = $("body").find("#2"); How do I do something like this: row_id = 5; row = $("body").find(row_id); The above syntax produces an error. I checked the jQuery documentation and answers here without success. ...

have a select and want to also retrieve count of the records

Dim db2 As New NewsDataContext Dim filter As String = "System" Dim Msg = From m In db2.Blog_Messages _ **From c In db2.Blog_Comments _** Join u In db2.users On m.userID Equals u.userid _ Where m.userID.Equals(filter) _ **Where c.MessageID.Equals(myRec) _** Group c By c.MessageID I...

States and Countries select box - best way to do it?

Hi guys, this may seem trivial but I'm setting up, on a profile form page I'm building, a countries and states select box such that when you select the US or Canada then the states box would display states of the selected countries else it would display a None Applicable instead. My countries and states are in a database and I'm populati...

Implementing and applying a string split in T-SQL

I have this statement in T-SQL. SELECT Bay From TABLE where uid in ( select B_Numbers from Info_Step WHERE uid = 'number' ) I am selecting "multiple" BAYs from TABLE where their uid is equal to a string of numbers like this: B_Numbers = 1:45:34:98 Therefore, I should be selecting 4 different BAYs from TABLE. I basically need t...

TOP N problem with GROUP BY clause

The problem: I need to find all active [GiftPledges] that have the last three [GiftDetails] have a zero amount. SELECT gp.PledgeId FROM GiftPledge gp INNER JOIN GiftDetail gd ON gp.PledgeId = gd.PledgeId WHERE gp.PledgeStatus = 'A' GROUP BY PledgeId HAVING COUNT(PledgeId) >= 3 Now, I have all my [GiftPledges] t...

MySQL: Selecting rows ordered by character count

In MySQL, how can I order my query by character count? ...

How can I properly use a PDO object for a Select query

I've tried following the PHP.net instructions for doing Select queries but I am not sure the best way to go about doing this. I would like to use a parameterized Select query, if possible, to return the ID in a table where the name field matches the parameter. This should return one ID because it will be unique. I would then like to us...

MySQL : selecting the X smallest values

Hi, Let be a table like this : CREATE TABLE `amoreAgentTST01` ( `moname` char(64) NOT NULL DEFAULT '', `updatetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `data` longblob, PRIMARY KEY (`moname`,`updatetime`) I have a query to find the oldest records for each distinct 'moname', but only if t...

mySQL: select * in combination with UNIX_TIMESTAMP

Right now I'm retrieving data from my database as follows: SELECT id, UNIX_TIMESTAMP(cdate) as myunixdate, permalink, title FROM mytable But I would like to do it as follows, but it doesn't work. SELECT *, UNIX_TIMESTAMP(cdate) FROM mytable My question is, how can I combine UNIX_TIMESTAMP without having to specify all the other field...

MySQL Selecting wrong column value in Group By query

Here's a real noobish MySQL query problem I'm having. I have a high score table in a game I'm writing. The high score DB records a name, level, and score achieved. There are many near duplicates in the db. For example: Name | Level | Score | Timestamp (key) Bob 2 41 | 1234567.890 Bob 3 15 | 1234568.890 Bob 3 ...

disable value in s:select

Hi, if I have a for example this struts tag: <s:select name="country.id" list="countries" listValue="name" listKey="id" headerValue="Select Country" headerKey="" label="Country" /> output is the following html code: <select name="country.id" tabindex="12" id="registration_country"> <option value="">Select Country</option> <opt...

[DB2] Order a select result case insensitively?

Is it possible to order the result of select query on a db2 database case insensitively? For example: I want to have all names that start with an "a" or "A" sorted together. Abraham aron andrea Annica brian Benjamin Now it's like this: aron andrea brian Abraham Annica Benjamin ...

select rows in a one to many situation

Hi everybody! I think that I am stuck with this particular situation: Here are my tables: item_table: id | item 1 : A 2 : B 3 : C attr_table: attr | item_id 1 : 1 1 : 2 2 : 1 2 : 3 3 : 2 3 : 3 I would like to know if it is technically possible to retrieve any item which is associated with attr = 1 and 3. The answer shoul...

SQL Server Index - Any improvement for LIKE queries?

We have a query that runs off a fairly large table that unfortunately needs to use LIKE '%ABC%' on a couple varchar fields so the user can search on partial names, etc. SQL Server 2005 Would adding an index on these varchar fields help any in terms of select query performance when using LIKE or does it basically ignore the indexes and d...

How do I get a count of associated rows in a left join in MySQL?

I have two tables, a vehicle table with columns: id stock year make model and an images table with columns: id vehicle_id name caption default tinyint(1) I am trying to list the vehicle's information, its default image, and a total count of images the vehicle has. Currently I am using the following SELECT statement: SELECT vehi...