Does this query will be faster with a index on "t.type1" and "x.type1" or only index on "x.type1" is enought?
SELECT t.id, x.id
FROM t
INNER JOIN x ON x.type1=t.type1
WHERE t.id=1
iam having an array of items like
[item1,itmem2,item3];
i have to insert these items at a particular userId:
final results look like this
UserId ItemId
2 || item1
2 || item2
2 || item3
currently iam looping through the array in php code and inserting each item one by one eg
foreach($items as $item)
{
insert into items (UserId,ItemId) value (2,$item);
}
is it possible i can insert all entries in single query.
Hi,
I have a project in C# with a Sql-server Database.
In that database I have a table named 'Process' and columns named 'process_name', 'Full_Name' and 'Version' (all of the type:nvarchar(50)).
I want to write a query wich will add the new process, only if it doesn't exist in the table yet.
How can I do that?
Many thanks,
In mysql a result of a query is
say select timestamp from newbie;
| 2010-03-12 14:50:46 |
| 2010-03-12 14:50:46 |
| 2010-03-12 14:50:51 |
| 2010-03-12 14:50:52 |
| 2010-03-12 14:50:54 |
| 2010-03-12 14:51:04 |
| 2010-03-12 14:51:07 |
| 2010-03-12 14:51:08 |
Is there a way to subquery the above and sum up the i.e, the final result should be the delta of each row in hh:mm:ss format
I am using CakePHP for a price-comparison website.
I have a table products with fields: id, pride_regular, price_action.
I would like to combine the fields price_regular and price_action into a dynamic field: price. The lowest value of these two fields should be the value of the new price field. Also I want to order on it Ascending.
Should I use a custom MySQL-query?
I have this query:
$theQuery = mysql_query("SELECT phrase, date from wordList WHERE group='nouns'");
while($getWords=mysql_fetch_array($theQuery)) {
echo "$getWords[phrase] created on $getWords[date]<br>";
}
The data table "wordList" contains 75,000 records in the group "nouns" and every time I load the code I am returned an error. Help!
Hi all
I have a question about PHP Class. I am trying to get the result from Mysql via PHP. I would like to know if the best practice is to display the result inside the Class or store the result and handle it in html.
For example, display result inside the Class
class Schedule {
public $currentWeek;
function teamQuery($currentWeek){
$this->currentWeek=$currentWeek;
}
function getSchedule(){
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if (!$connection) {
die("Database connection failed: " . mysql_error());
}
$db_select = mysql_select_db(DB_NAME,$connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
}
$scheduleQuery=mysql_query("SELECT guest, home, time, winner, pickEnable FROM $this->currentWeek ORDER BY time", $connection);
if (!$scheduleQuery){
die("database has errors: ".mysql_error());
}
while($row=mysql_fetch_array($scheduleQuery, MYSQL_NUMS)){
//display the result..ex: echo $row['winner'];
}
mysql_close($scheduleQuery);
//no returns
}
}
Or return the query result as a variable and handle in php
class Schedule {
public $currentWeek;
function teamQuery($currentWeek){
$this->currentWeek=$currentWeek;
}
function getSchedule(){
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if (!$connection) {
die("Database connection failed: " . mysql_error());
}
$db_select = mysql_select_db(DB_NAME,$connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
}
$scheduleQuery=mysql_query("SELECT guest, home, time, winner, pickEnable FROM $this->currentWeek ORDER BY time", $connection);
if (!$scheduleQuery){
die("database has errors: ".mysql_error());
// create an array }
$ret = array();
while($row=mysql_fetch_array($scheduleQuery, MYSQL_NUMS)){
$ret[]=$row;
}
mysql_close($scheduleQuery);
return $ret; // and handle the return value in php
}
}
Two things here:
I found that returned variable in php is a little bit complex to play with since it is two dimension array. I am not sure what the best practice is and would like to ask you experts opinions.
Every time I create a new method, I have to recreate the $connection variable: see below
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if (!$connection) {
die("Database connection failed: " . mysql_error());
}
$db_select = mysql_select_db(DB_NAME,$connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
}
It seems like redundant to me. Can I only do it once instead of calling it anytime I need a query? I am new to php class. hope you guys can help me. thanks.
I want to insert a record into a sqlite table if its actually not inserted.
Let's say it has three fields pk, name, address
I want to INSERT new record with name if that name not added preveously.
Can we do with this in a single Query. Seems like its slightly different from SQL Queries sometimes.
Thanks you,
Tharindu Madushanka
I am sure I can improve the performance of the following findByName query of hibernate:
public List<User> findByName(String name) {
session.createCriteria(User.class).add(Restrictions.eq("name", name)).list();
}
In which way should I improve it or even more important: in which ways should I improve it first? I will need the full object with all the collections (layz or not) and deps of this class.
Suppose I have a column with words:
orange
grape
orange
orange
apple
orange
grape
banana
How do I execute a query to get the top 10 words, as well as their count?
I currently have two tables:
1. car(plate_number, brand, cid)
2. borrow(StartDate, endDate, brand, id)
I want to write a query to get all available brand and count of available cars for each brand
hi!
the query is:
select employee_id, last_name, salary, round((salary+(salary*0.15)), 0) as
NewSalary, (round((salary+(salary*0.15)), 0) - salary) as “IncreaseAmount”
from employees;
can i optimize this round((salary+(salary*0.15)), 0) part in anyway, so that it doesn't appear twice..i tried giving it an alias but didn't work :(
Say we have a table
table posts
+---------+-----------+--------------------------------+
| postId | title | status | bodyText |
+---------+-----------+--------------------------------+
| 1 | Hello! | deleted | A deleted post! |
| 2 | Hello 2! | deleted | Another one! |
Can we, in SQL, retrieve a concatenation of a field across rows, by issuing a single query, not having to do the join up in a loop in our back-end code?
Something like
select title from posts group by status ;
Should give "Hello!, Hello 2!"
iam having 2 tables
table Items Table (this table holds all items iam having)
itemId
---------
Item1
Item2
Item3
Item4
Item5
table 2 users_item relation
UserId || ItemId
1 || Item1
1 || Item2
userId one has stored 2 items Item1,Item2.
Now i want to write a query on table1 (Items table) so that it displays all items which user1 has NOT chosen.
Hello all i have a problem that i just CANT get to work like i what it..
i want to show news and reviews (2 tables) and i want to have random output and not the same output
here is my query i really hope some one can explain me what i do wrong
SELECT
anmeldelser.billed_sti ,
anmeldelser.overskrift ,
anmeldelser.indhold ,
anmeldelser.id ,
anmeldelser.godkendt
FROM
anmeldelser
LIMIT 0,6
UNION ALL
SELECT
nyheder.id ,
nyheder.billed_sti ,
nyheder.overskrift ,
nyheder.indhold ,
nyheder.godkendt
FROM nyheder
ORDER BY rand() LIMIT 0,6
i have stored in the database as
location
India,Tamilnadu,Chennai,Annanagar
while i bind in the grid view it ll be displaying as
'India,Tamilnadu,Chennai,Annanagar' this format.
but i need to be displayed as 'Annanagar,Chennai,Tamilnadu,India' in this format. how to perform this reverse order in query or in c#
I have a sample Solr schema as follows
isPublic = boolean
source = facebook| twitter | wordpress
I want to write a query which returns all documents from the index which matches either the isPublic = true or isPublic is false and source= facebook. Something like this
solrUrl/?q=blah&fq=(isPublic:true OR (isPublic:false AND source:facebook))
Is such a thing possible or should I search the index two times with each of these conditions and then combine + de-duplicate the results?
I'd like to get a better idea of what domains my customers are using. I could easily do this in PHP by explodeing each address and counting the domain that way. But I'm wondering if there's a way to get this information with just a plain MySQL query?
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?
i have table country and having country name and country code,
i have customer table having countomer mobile number like customer_mobile field values like 0044-123456798 ,
0024-582654753 , 012-52686145 ,
i want to populate my country oce into combo,
that country name should in customer table which country code count is high that country name should come in the
dropdown list top ,
How to write the join query...
Thanks
Here's the query:
INSERT INTO jobemails (jobid, to, subject, message, headers, datesent) VALUES ('340', '[email protected]', 'We\'ve received your request for a photo shoot called \'another\'.', 'message', 'headers', '2010-04-22 15:55:06')
The datatypes are all correct, it always fails at the subject, so it must be how I'm escaping the values, I assume.
I'm sure one of you will see my idiot mistake right away. A little help?
I need to write a query that creates a view that calculates the total cost of each sale, by considering quantity and price of each bought item. The view should return the debit and total cost.
In the answer each debit-number should only occur once.
Thanks in advance
Table ITEM:
ID NAME PRICE
118 Jeans 100
120 Towel 20
127 Shirt 55
Table DEBIT:
DEBIT ITEM Quantity
100581 118 5
100581 120 1
100586 127 5
I need to retrieve data from within a specific date range.Anybody can help me to create a query to getting the information within date range 12-12-2009 to 12-15-2009 from a mysql table.(including 12 and 15)
i have interest rate and amount in a table where interest rate are ranged in different values
like 4.5,4.6,5.2,5.6 etc.
i want to get sum of amounts classified by interest rate where interest rate will be separated
by .25.
for example all amount having interest rate 1.25,1.3,1.4 will be in one group
and 1.5,1.67,1.9 will be in another group
how can i write the query?
I'm writing an InfoPath web form, using C# code behind. The form is a holiday request, after the user inputs the start and end dates I want the code to query a bank-holiday sharepoint list and count occurrences between the dates.
I've added the sharepoint list as a second datasource however I'm now stuck. Any ideas?