query

JPA @NamedQuery with two tables, possible??

Hi all, I'm having a kind of dummy problem, I need to make a @NamedQuery with a join with other table, some simple thing. But in all my @NamedQuery I'm only dealing with my mapped Object/Table. For example in my Object/Table Mapped cars: @NamedQuery(name = Cars.GET_AVAILABLE_CARS, query = "select c.id from Cars c where c.status = (s...

Query on hibernate entity with user-type field

Hey, working with JPA above hibernate impl. I map my enums by using user-type follow the good practice to store a persistence key to the enum and not the ordinal (which can be changed). Now, i have a problem to query on the enum field. it seems that hibernate dont execute the user type convert on the name-query. Any idea? ...

datetime in where clause

how can i select 12/20/2008 in where clause of sql. it is sql server 2005. select * from tblErrorLog where errorDate = '12/20/2008' ...

Help needed in AdventureWorks in a sql query.

I was just playing with adventureworks database in sqlserver. I got stuck in a query. I wanted to Select all titles from HumanResources.Employee which are either 'Male' or 'Female' but not both. i.e if title Accountant is Male and Female both I want to leave that title. I need only those titles where Gender is either Male or Female. I h...

Subreports are not getting printed.

I tried to create a very simple report with a subreport. The subreport was created separately and was embedded in the data group. The subreport separately gives me the relevant data. and the other main report gives me the intended partial data. But the data intended in the place where the subreport has been embedded is not appearing. It ...

MySQL: Select distict field, but get the rest of the columns as well?

I want to select distinct product_series, but I want all the other columns too. This is my query as it stands: SELECT DISTINCT product_series FROM cart_product WHERE product_brand = "everlon" AND product_type = "ring" AND product_available = "yes" But this only gives me product_series, but I need all the other columns in that row...

Add total to group.

I have a Order Details table. What I want to do is create 1 query to show OrderNumber | SKU | QTY | Price | Line Total | 1 SKU1 1 10.00 10.00 1 ---- 0 0.00 10.00 2 SKU1 2 10.00 20.00 2 SKU2 3 1.50 4.50 2 ---- 0 0.00 ...

apostrophes are breaking my mysql query in PHP

My database has name records that occasionally contain apostrophes, such as Joe's Bar and I've just coded a query script in PHP that grabs that field and sticks it into a select statement with the usual $query = "SELECT address FROM restaurants WHERE name='$name'"; and the apostrophe in some of the restaurant names derails the Love Train...

Extract all the data from a database

Hey, I am wondering how to extract the data from a table in a database onto a table in a page (users.php), For example: I want to be able to get all of the usernames and all the id's from my database onto a table. So if I have in my database: 1 - Fred 2 - Frank 3 - Margret It will see that I have them user's and id's in the database...

Q>Query in Order/Purchase History of Northwind database.

How can I select query the order/purchase history in northwind database? There are 2 tables(orders and purchase order table) then connected to Inventory Transaction table. ...

Django - How to remove F() from a field?

Hello guys, after doing a query with F() (see http://docs.djangoproject.com/en/dev/topics/db/queries/#query-expressions), I save the object, but then, I need to save it again. I want to remove F() from the field. If I don't, F() gets called again. For example rank.ammountMatchesRanked = F('ammountMatchesRanked') + 1 rank.save() # does ...

How to join SQL tables while selecting a COUNT() function?

I have two database tables, 'Lists' and 'Notes'. Lists has columns _id, listname Notes has columns _id, checked, list_id (which is a foreign key of Lists._id), and more columns that aren't relevant to this question. I would like to create a query that returns four columns: Lists._id, Lists.listname, the count of all checked Notes in thi...

SQL query - group by timespan in MySQL

I have a table containing the following details: date_info info 2009-06-23 1 2009-06-24 2 2009-06-25 20 2009-06-26 14 2009-06-27 17 2009-06-28 5 2009-06-29 10 2009-06-30 2 etc. I would like to group the info coloumn by occurrences per week and month, like so: 2009-06-01_2009-06-07 XXX 2009-06-08_2009-06-14 XXX Grouping by...

Pass an array as value in an ado.net DBParameter

The project I'm working on has a lot of IN-queries like: SELECT something, anotherthing FROM atable WHERE something IN (value1, value2, value3) This is an example of a queru with 3 parameters in the IN-part but the same query could be executed with 1 or 2 or 5 or 10 or ... parameters. The problem is that each query has an other execut...

Hibernate Criteria / Query on object properties

I have a class AppUser; class AppUser { private String firstName; private String lastName; //-- getters and setters } I also have another class Student; class Student { private AppUser appUser; private Date dateOfBirth; //-- getters and setters } How would i search for Student John Doe, firstName John, lastName Do...

How to select from joined MySQL tables?

I basically have two tables: A(id int, name varchar(10), info varchar(10)) B(id int, item varchar(10)) A 1 A Hello 2 B World 3 C Foo B 1 apple 1 orange 1 hammer 2 glass 2 cup Using the following query... mysql> SELECT a.id, a.name, a.info, group_concat(b.item SEPARATOR ' ') FROM a LEFT OUTER JOIN b ON (a.id=b.id) ...

Built-in method for finding a specific instance of an object in PHP?

I really am clueless when it comes to object-oriented programmings, so forgive me if this is obvious... I am using a Zend extension which returns a request as a nested object. I need property a based on if the object has property b. Right now I am using a foreach loop with a conditional to search for property b and, if I get a match, se...

Optimizing my mysql query to use index for sorting

Dears, I need your help to optimize the query below. Let us assume we have a web application for articles. The software use two table;one is the article table and the second one is the users table. The article table hold the date when the article is created,the id,the body,the title & the section. Let us assume that we have one section ...

R accessing DB query results by column and row number

Hi, I am new to R language. I have successfully loaded a query's resultset into a variable. Now I want to access the resultset data by column name and row number. And I need to verify if it is Null (it is shown as < NA > in result) then send a mail by bat file with php. My sample code is below. library(RODBC) newconn = odbcConnect("db...

Please help me convert a Linq Query to a SQL Query... Desperate...

Hey all, Im pretty proficient in LINQ, but not in SQL. I understand cursors are horrible and shouldn't be used. I know SQL Syntax pretty well, but I am trying to figure out how to convert this query and update to SQL from Linq. I don't know how to go through the Foreach of SQL without using cursors and Im a bit lost on what to do ne...