query

prevent insert while select query, hibernate

Hi, new to hibernate. I have a problem that when i am trying to run select query say "from Foo where Foo.some_id=2" (with hibernate template) then hibernate is also tries to insert the records in a table 'Foo2' that has a one-2-one association with the Foo table Bean Foo class Foo{ int id; .... Foo2 foo2; } Foo.hbm.xml ... <one...

PHP - SQL query Syntax Error

I'm having a hard time finding the error that exists in my script. Can anyone help me spot it? case "process_movie_order": // handle POST if ($_POST) { //Drop "order" column and Re-ADD it to reset ID #'s $droppedresult = mysql_query("ALTER TABLE videos DROP COLUMN order"); $add...

mysql split search string by space and push into query

The search query is: "product1 prod2 prod4" I need to make the mysql SELECT * FROM tableprod WHERE (prod LIKE '%product1%' AND prod LIKE '%prod2%' AND prod LIKE '%prod4%') using the mysql_real_escape_string for the input query... ...

age from dob in sql

In the sql query, I am getting problem in the where clause. I have a dob and ssn of people in a table. I need to find the youngest snr. customer. The age of youngest senior customer starts from 55. The data of DOB contains all the dob's of children,parent, senior customers. In the line "where" I have to write a condition that checks if ...

query in sql database

Hi, How do we find the top 2 most populated cities i.e where no. of customers are higher than any other.I only have the SSN of the customers. They are unique and I am thinking of counting them for a particular city and check if that is higher than any other city. ...

django: datediff sql queries?

I'm trying to do the equivalent of the following SQL in Django: SELECT * FROM applicant WHERE date_out - date_in >= 1 AND date_out - date_in <= 6 I can do this as a RAW sql query, but this is becoming frustrating in dealing with a RawQuerySet instead of a regular QuerySet object as I would like to be able to filter it later in the code...

Is there any .net class for query conditions like DetachedCriteria in Hibernate, but not rely on Hibernate?

I'm writting a general DAO interface and facing a difficult in general Query operation. Query operation requires a set of query conditions. I'd like to give a interface like IList<TEntity> Query(DetachedCriteria criteria); But this makes the interface rely on nHibernate. If I want to use Linq or plain SQL, it is not easy to convert D...

error in sql query

I am writing an query in sql and getting an error: Invalid use of group function What does it mean? In my query, where clause is given below: select c.name,s.contact,s.number from list c , senior s where c.id = s.id AND c.name = 'Abg' AND c.state ='qw' AND MIN(c.dob); Basically, I have 2 files and I need to find the younger custome...

mysql query on dob

If DOB is given in this porder- 1853-03-12 , then how do we find the youngest person from table bases on this type of data. If the year is same but month is different for 2 persons. I tried MIN(dob)- it gives me the oldest person and When I tried MAX, it gives me nothing. ...

Android - Query String instead of integer

Hello. I am trying to query a string (TEXT field in the database) and want to fetch records based on that query. I was following a tutorial which works fine if I query an Integer (the _ID field). What will I need to change in the code below to let it search for the string (the TEXT field) instead of the _ID field? The activity code: pr...

SQL Server query with null value

In my C# code, I have to do an SQL Query like this : context.ExecuteStoreQuery("SELECT * FROM MyTable WHERE Field0 = {0} AND Field1 = {1}", field0, field1) When field1 = null in c# and NULL in database this query doesn't work. (I have to use a different syntax with IS NULL) How can I correct this without make an if (in reality, ...

sqlalchemy query refresh issue after use mysql load file

i use a sqlalchemy as my orm,i do a mysqlimport cmd through subprocess,and before & after the execution i query the db records,which i use statistics_db method, but the records count results after import from csv didn't increase,i think this is a sqlalchemy problem,how to slove this?,thanks def statistics_db(f): @wraps(f) def wr...

Query not work in CodeIgniter

function menuName () { $this->viewData['page_title'] = "ContentManagement Systemt!"; $this->db->where('visible', 1); $this->db->order_by("position", "ASC"); $query = $this->db->get('subjects'); $subjects = $query->result(); foreach ($subjects as $subject) { echo $subject->menu_name ."<br />"; ...

DB2 Case Sensitivity

I'm having great difficultly making my DB2 (AS/400) queries case insensitive. For example: SELECT * FROM NameTable WHERE LastName = 'smith' Will return no results, but the following returns 1000's of results: SELECT * FROM NameTable WHERE LastName = 'Smith' I've read of putting SortSequence/SortType into your connection string b...

SQL Query Formatting

SELECT `accounts`.`password` FROM accounts WHERE `accounts`.`user`='some_user' SELECT password FROM accounts WHERE user='some_user' I am a bit confused about the two. I know as far as the results, there is not a thing different between the two. However is there some reason to do one way as opposed to the other? I learned it the second...

Query>Checking with Today Date in VB

I have created the database in Microsoft Access with this query SELECT * from booking WHERE BOOK_DATE = DATE() order by book_time* it returns 3 records which has BOOK_DATE = today date but... when i tried to place it in the Visual Basic with Data Control and DBGrid, i enter the query in the RecordSource property, but the data didn...

How to get only one set of data from my Stored Procedure?

I'm using SQL Server 2000. My SP produces the follwing output: It sums up all Taxable Earnings (top result) and subtract it by the sum of Deductible Expenses (middle result) to get the Net Taxable Income of an employee. How will I get the value of Net Taxable Income only? Here's my SP /* DECLARE @NET_TAXABLE_INCOME AS NUMERIC(19...

sql question, alternative to if-else for this example?

Hi Guys, DECLARE @cityID bigint; set @cityID = NULL --set @cityID = 3 SELECT ID, Name, CityID, IsProvince FROM TABLE t WHERE ISNULL(t.CityID, -1) = ISNULL(@cityID, -1) whenever the @cityID is NULL the t.CityID is also NULL for that record. Only one record can ever be true for IsProvince Is there a way to...

Return custom value if join not successfull ?

I am trying to do a select which would return a blank '' when a join is not successfull (when a blank '' or a '-' is encountered in column) and return column value when it is successfull. I am using case for this but not succeeding until now. Anyone can advise a better query ? select a.EmpName,a.deptcode,(a.deptcode||' '||(SELE...

Update with value from a select query in Linq To SQL

Update TableToBeUpdated Set ColumnNameId = (Select MasterColumnId from MasterTable where Id = @Id) Where ForeingKeyId = @Id AND AnotherColumn = @AnotherColumn How to achieve the above with one select statement and an update statement with a subquery? Currently what I'm thinking is. //First Select statement ...