sql

Query by age in hql

I have a class User with one field called birthDate which is a java.sql.Date. How do I do a hql query that will retrieve all Users that are between min and max years old? (My real scenario is slightly more complex than that but that's where I am stuck right now). UPDATE It must be an hql expression so I can put the age expression in a...

SELECT question

Let's say I have a table containing a list of cities: city | latitude | longitude --------------------------- XX | 34.800 | 48.550 Assuming I have an approximate location (latitude/longitude) of a user, how do I find the city that is nearest? That is, how do I find the city whose latitude and longitude is closest to the user's lat...

SQL syntax to combine several tables

I need to display a single list, ordered by date which contains different types of data, images, video and whatnot. I guess you could have one separate table for each type and the use something like FULL OUTER JOIN (simulated as sqlite doesn't support it) and sort on date. But this would be complicated because I still need to have uniqu...

MySQL query to select 2 columns using the same select pattern

I have to perform a select on a table in the following manner: I am searching for some strings in 2 columns, the search string can be in either one or the second, or in both. To select from a single column I would use something like: SELECT * FROM table WHERE TITLE LIKE '%pat1%' OR TITLE LIKE '%pat2%' OR TITLE LIKE '%pat3%' etc. Th...

UPDATE Multiple Rows Using CASE in SQL 2008

Hi, I have the following sql statement where i'm trying to update multiple rows matching a select statement. UPDATE Cars SET engineSize = CASE specCode WHEN 1 THEN value ELSE engineSize END FROM Cars INNER JOIN CarSpecs ON CarsSpecs.carID = Cars.carID My tables are as follows: Cars carID engineSize ... 1 0 2 0 CarSp...

PHP & SELECT how to?

I want to show what the user($pusername) have been posted, in member_film, member_meetups, member_tutorials.. And then if e.g the user have 2 columns with his username, i want to display the "navn" from the same column. Same with title on member_tutorials, and meetup on member_meetups. An example on how i want it to look like: Your pos...

default value, oracle sp call

I have an oralcle SP forced on me that will not accept an empty parameter in an update. So if I wanted to set a value back to the default of ('') it will not let me pass in the empty string. Is there a keyword you can use such as default, null, etc that oracle would interpret back to the default specified for a particular column? ...

MySQL delete from 3 tables

Hi There, I have the following tables, with these keys in my database: bookings session_id sessions session_id course_id courses course_id I want to create a query to delete all date relating to a single course (course_id). For example if I wanted delete course_id=10, I would want any sessions with course_id=10 to be deleted, in add...

MySQL Syntax Error; "check the manual that corresponds to your MySQL server version.."

I've been looking all over the internet for a solution to the following error; "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'primary, username, password, password2) VALUES (null, 'hello', 'hello', 'hello')' at line 1" I have no idea what is going...

null values in mySQL

I've got a new website moved to my server. This website uses PHP and MySQL, and is built very poorly. The problem is - it needs non-null values inserted into new records where ever I don't specify a value, though the default value is null. I've been told it has been done on the previous server, but they have no idea how. I'd be glad t...

Recursive subdirectory SQL problem

This is a mental excercise that has been bothering me for a while. What strategy would you use to solve this sort of problem? Let's consider the following simple database structure. We have directories, obviously a tree of them. Also we have content items, which always reside in some directories. create table directory ( directoryId ...

MySQL: value based on conditions

I have a MySQL query where I would like it to have a pseudo column returned which is based off of: If columnW does not equal 0, it should be 1 BUT If columnX does not equal 0, it should be 2 BUT If columnY does not equal 0, it should be 3 BUT If columnZ does not equal 0, it should be 4 Hopefully that makes sense. My SQL isn't good en...

Latest Actions in PHP?

If you go to http://www.foxnews.com, and scroll down a little you would see the box "LATEST NEWS". Now I want to do something like that, but with modification. I have 3 queries, that get out information from 3 tables. But this doesn't give me the "latest news", because it's 3 separate queries. Now I want to make a box, (I can do this ...

beginning: sql server 2008 express with mdf file

i want to practice connecting from asp.net to a sql server database. i have it in mdf file. please help me. what is the next step? i got the sample mdf database from here: http://msftdbprodsamples.codeplex.com/releases/view/37109 ...

express sql server 2008 book

hi can someone recommend a book that gives a good curriculum of how to do sql in sql server 2008? ...

Efficient GridView Paging... not quite getting it

I'm trying to wrap my head around custom paging in the ASP.NET Gridview, but all of the examples I read seem to be bloated with stuff I don't need (Scott Gu's for example). Can someone point me in the right direction to a tutorial that is easy to understand the basics? EXAMPE: If I have the following Stored Procedure... Alter Proce...

TSQLConnection to a user chosen DSN at runtime

Hi, I want to use dbExpress and a TSQLConnection object to allow the user of my application to connect to any of their ODBC dsn and run a SQL query against it. I have it so the user can select a DSN, (by DSN i mean all the configured data sources listed in control panel - administrative tools - Data Sources (ODBC)), but once they have ...

Sorting based on the count in a related field in Django

I have two models, Image and Tag. Each Image object can have more than one Tag associated with it, and I want to find my most frequently used tags. How would I go about this? It seems easy enough but I can't seem to figure it out. ...

Store Procedure Select into a variable

How can I count the result of a table and pass into a Stored Procedure Variable? DECLARE @totalrecs varchar select count(id) from table1 I want the count record in the totalrecs variable. ...

Insert XML into SQL Table XML column

Am trying to insert XML into XML Column.. getting following error: . Msg 6819, Level 16, State 1, Line 5 The FOR XML clause is not allowed in a INSERT statement. My SQL query declare @tempTable Table (xmlValue xml) insert into @tempTable select EmployeeName, EmployeeSalary from Employee2 for xml path('EmployeeDetails') what am i doi...