query

advanced search with mysql

I'm creating a search function for my website where the user can put in anything he likes in a textfield. It get's matched against anything (name, title, job, car brand, ... you name it) I initially wrote the query with an INNER JOIN on every table that needed to be searched. SELECT column1, column2, ... FROM person INNER JOIN person_c...

How to get the last element by date of each "type" in LINQ or TSQL

Imagine to have a table defined as CREATE TABLE [dbo].[Price]( [ID] [int] NOT NULL, [StartDate] [datetime] NOT NULL, [Price] [int] NOT NULL ) where ID is the identifier of an action having a certain Price. This price can be updated if necessary by adding a new line with the same ID, different Price, and a more recent date....

LINQ dynamic query

How to dynamically generate LINQ query: int[] IDArray = {55, 36}; public IQueryable<ContactListView> FindAllContacts(int loggedUserID, int[] IDArray) { var result = ( from contact in db.Contacts //Start of dynamic part... where contact.UserID == loggedUserID ...

LINQ entity query performance

Hi all, I have a silly question. I would like to know if there is performance deference in these two quries: var cObject = from cust in entities.Customer where cust.id == cid select cust; and var cObject = entities.Customer.First( c=> c.id == cid); My query return only one record as I am querying with the prima...

Query with UDF works in Access but gives Undefined function in expression (Err 3085) in Excel

I have an Access table with a date/time field. I wanted to make a composite Key field out of the date/time field and 3 other text fields in the same format as the matching Key field in another database. So I concatenated the 3 text fields and wrote a User-Defined-Function in a Module to output the date field as a string in the format "Y...

Not sure how to use Decode, NVL, and/or isNull (or something else?) in this situation

I have a table of orders for particular products, and a table of products that are on sale. (It's not ideal database structure, but that's out of my control.) What I want to do is outer join the order table to the sale table via product number, but I don't want to include any particular data from the sale table, I just want a Y if the jo...

Effects of order of columns, while defining an index on them, on the performance of the queries

Hi, Does order of the columns in an Index definition for a table in a database has any effect on the performance? for e.g. are these two queries different ? CREATE INDEX xxx ON tablex(col1,col2) CREATE INDEX xxx ON tablex(col2,col1) what about the in case that I use a BTREE index? I am using Mysql. thanks ...

Retrieving multiple rows from a loop-created form... Stuck.

Let me start by saying that I'm new to PHP, but I'm here to learn and would really appreciate your help. I use the following code to pull in data and create a form. This creates up to 40 lines for a user to fill out. Each line consists of the same information: Description, Amount, and Frequency. The remainder of the information needed ...

Mysql many to many problem (leaderborad/scoreboard)

Hi all! I'm working on a small project in regards of the upcoming World Cup. I'm building a roster/leaderboard/scoredboard based on groups with national teams. The idea is to have information on all upcoming matches within the group or in the knockout phase (scores, time of the match, match stats etc.). Currently I'm stuck with the DB in...

how to get the 30 days before date from Todays Date

how to get the 30 days before date from Todays Date. in Sql using Query ...

SQL most executed query?

Hi everyone, I have a database in SQL Server 2008, and there are a lot of machines making queries against it. I know there is a SQL Server profiler, but I don't know very well how to use it. Is there any way to know what are the most common queries executed in the database? Through the profiler or not, it doesn't matter. Thank you ver...

how to use the order by and aggregate function together in sql query

SELECT count(distinct req.requirementid), req.requirementid, org.organizationid, req.locationofposting, org.registereddate FROM OrganizationRegisteredDetails AS org, RequirementsDetailsforOrganization AS req WHERE org.organizationid = req.requirementid ORDER BY org.RegisteredDate desc this shows me the error...

Best way to add a column in mysql query

Can any one please let me know that, I need to add a column dynamically when executing mysql query Table: Table1 -------------------------- col1 col2 col3 -------------------------- Test OK Test3 Test OK Test5 Test OK Test6 from the above example i need to introduce "col2" as new column and ...

Ordering recursive result set in SQL Server

I am having extreme difficulty constructing a query which returns an XML style hierarchy. We have a database table which contains a hierarchy of URLs for our website. The table contains the columns: ID, URL, DisplayName, ParentID, ItemOrder The parent ID forms a recursive relationship between the current item and it's parent. The item ...

pgSQL query error

i tried using this query: "SELECT * FROM guests WHERE event_id=".$id." GROUP BY member_id;" and I'm getting this error: ERROR: column "guests.id" must appear in the GROUP BY clause or be used in an aggregate function can anyone explain how i can work around this? ...

How to update multiple rows with one single query

I use Postgresql + PHP. Say I have this table: Books ( id, title, year ) and this array of titles in PHP: $titles = array ("bible","kafka","Book of Eli"); now I want update all rows where the title is in the $titles array above. So I need a query like this: UPDATE books SET year = '2001-11-11' WHERE title is in $titles; Is is ...

help with sql query - in access 2007

hi i have 2 tables table items has 144602 records table A has 27721 records code in items = BAR8 in A i want to show all records that equal i try this: SELECT Items.Code, A.BAR8 FROM Items INNER JOIN A ON Items.Code = A.BAR8; and i get 28048 records !!! i need to get 27721 , how to do it ? thank's in advance ...

MySQL: Ignore the timestamp attribute

I have a timestamp column in my database, and i use it for almost every field, but now, i just want to update the hit counter.. and i do not want to update the timestamp column with it. I use the timestamp field to see the last 'content' update. Not for every hit. Is it possible to let mysql stop updating the timestamp column for just o...

Strange data swapping error occurs when I attempt to update rows in my table from another table in my sql database...please help!

So I have a table of data that is 10,000 lines long. Several of the columns in the table simply describe information about one of the columns, meaning, that only one column has the content, and the rest of the columns describe the location of the content (its for a book). Right now, only 6,000 of the 10,000 rows' content column is filled...

building SQL Query From another Query in php

When I Try to built Query from another Query in php code I Faced some problem can you tell me why? :( code : $First="SELECT ro.RoomID, ro.RoomName, ro.RoomLogo, jr.RoomID, jr.MemberID, ro.RoomDescription FROM joinroom jr,rooms ro where (ro...