"insert into NodeProfileSections (profile_no, tpl_section_no)
select (np.profile_no, tps.tpl_section_no)
from NodeProfile np, TemplateProfileSection tps, TemplateProfile tp
where np.hostname = '%s' AND np.role = '%s' AND tp.tpl_profile_no = tps.tpl_profile_no
AND tp.tpl_name = '%s' AND tp.role = '%s' AND tps.tpl_section_name = '%s';"
%(hostname, role, template_name, role, section_name)
error_message = 'Operand should contain 1 column(s)'
How to solve this problem?
I have this query (which I removed some keys from for brevity's sake):
SELECT id as in_id, out_id, recipient, sender, read_flag
FROM received WHERE recipient=1
UNION ALL
SELECT in_id, id AS out_id, recipient, sender, read_flag
FROM sent WHERE sender=1
Which combines the results from two tables showing messages sent and received by a given user. What I'd like to do is add a column/flag to the result to distinguish which table the row belongs to so when I display them I can show a relevant icon for sent or received messages. How would I add this?
I'm trying to use this code to check if the system already exists a field with this value
Dim adap As New MySqlDataAdapter
Dim sqlquery = "SELECT * FROM client WHERE code ='"+ TxtCode.Text +"'"
Dim comand As New MySqlCommand()
comand.Connection = con
comand.CommandText = sqlquery
adap.SelectCommand = comand
Dim data As MySqlDataReader
data = comando2.ExecuteReader()
leitor.Read()
If (data(3).ToString) = code Then
MsgBox("already exists", MsgBoxStyle.Information)
TxtCode.ResetText()
TxtCode.Focus()
Else
Console.WriteLine(insert("INSERT INTO client (name, tel, code) VALUES ('" & name & "', '" & tel & "')"))
con.Close()
End If
here is my query
$sql = 'SELECT *
FROM Orders
INNER JOIN [Order Details] ON Orders.OrderNumber = [Order Details].OrderNumber
WHERE
Orders.CartID =2
AND [Order Details].Option10 Is Null
AND [Order Details].Status="Shipped"';
this queries when entered in MS_Access sql view, returns the correct results,
but when I copy and paste the same query in my php script, it fails and gives the error
Too few parameters, expected 1...
although data is there, query is working in access...
Please note if I omitted on AND condition, it works eg if I removed shipped conidtion or is null condition, it works then too..
any hint? whats wrong with it?? any help?thanks
Hello, well the title says it all. Does anyone have an idea? Would need to lock the table for that long on production site, so it is kinda important.
Also, do you have any suggestion how such query could be optimized?
Thanks!
SELECT customer.id, customer.firstName, account.id
FROM customer, account
INNER JOIN customer
ON customer.id = account.customerId
ORDER BY customer.id
appologies for the poor editing...
I currently have this query which runs 2 of the exact same sub queries but pull different data. When I make the values comma separated it throws an SQL error saying the sub query can return only one value. Is there anything else I can do to avoid running multiple sub queries?
SELECT
product_id,
(
SELECT
COUNT(listing_id)
FROM ebay_archive_product_listing_assoc
WHERE product_id = product_master.product_id) as listing_count,
sku,
type_id,
(
SELECT
AVG(ebay_archive_listing.current_price),
AVG(ebay_archive_listing.buy_it_now_price)
FROM ebay_archive_listing
WHERE id IN (
SELECT listing_id FROM ebay_archive_product_listing_assoc WHERE product_id = product_master.product_id
) AND
ebay_archive_listing.start_time >= '.$startTimestamp.' AND
ebay_archive_listing.start_time <= '.$endTimestamp.' AND
ebay_archive_listing.current_price > 0
) as average_bid_price,
(
SELECT
FROM ebay_archive_listing
WHERE id IN (
SELECT listing_id FROM ebay_archive_product_listing_assoc WHERE product_id = product_master.product_id
) AND
ebay_archive_listing.start_time >= '.$startTimestamp.' AND
ebay_archive_listing.start_time <= '.$endTimestamp.' AND
ebay_archive_listing.buy_it_now_price > 0
) as average_buyout_price
FROM product_master
I'm aware of the syntax error... I'm selecting 2 seperate averages and am wondering if I can do it any simpler way.
I have a table with stock quotes that looks something like this:
id, date, stock_id, value
Every day has several rows for each stock_id (it is automatically updated every five minutes), so the table is rather big at the moment.
How do i delete every row but the last one each day for every stock_id?
i have two tables
table1 fields
fid,fname,fage
a ,abc ,20
b ,bcv ,21
c ,cyx ,19
table2 fields
rcno,fid,status
1 ,a ,ok
2 ,c ,ok
3 ,a ,ok
4 ,b ,ok
5 ,a ,ok
i want to display rectors like this
fid from table1 , count(recno) from table 2 and fage from table1
fid,count(recno),fage
a ,3 ,20
b ,2 ,21
c ,1 ,19
i try many sql queries but got error
Thanks
I am new to PhpMyAdmin.
I will like to create a foreign key for my tables.
In fact i have create tableI with this structures(A as int(11) autoincrement, B as varchar)
TableII ( A_2 as int(11) auto increment, B_2 as varchar, A as int(11).
I have declared A as an index in tableII, now when i go to relationship view to precise A as a foreign key i always have this error
Erreur lors de la création de la clé étrangère sur ID_Ville (vérifiez le type des colonnes)
Erreur
ALTER TABLE tb_quartier ADD FOREIGN KEY ( ID_Ville ) REFERENCES ingenieris2.tb_ville (
ID_Ville
) ON DELETE RESTRICT ;
Please Help
thanks!
What I am trying to do is: (programmatically)
Update status where id is something, if no rows where updated, give error: we cannot find the record with id something, otherwise give message success.
Here I am using mysql_affected_rows() to know if a row was updated or not, but it always return 1, so the user gets a success message, even though there was no row updated.
Can anyone tell me what could it be?
With a query such as:
SELECT * FROM images WHERE id IN (12,9,15,3,1)
is it possible to order the results by the contents of the IN clause?
The result I'm looking for would be something like:
[0] => Array
(
[id] => 12
[file_name] => foo
)
[1] => Array
(
[id] => 9
[file_name] => bar
)
[2] => Array
(
[id] => 15
[file_name] => baz
)
...
hello friends,
I have a very big table (nearly 2,000,000 records) that got split to 2 smaller tables. one table contains only records from last week and the other contains all the rest (which is a lot...)
now i got some Stored Procedures / Functions that used to query the big table before it got split.
i still need them to query the union of both tables, however it seems that creating a View which uses the union statement between the two tables lasts forever...
that's my view:
CREATE VIEW `united_tables_view` AS select * from table1 union select * from table2;
and then i'd like to switch everywhere the Stored procedure select from 'oldBigTable' to select from 'united_tables_view'...
i've tried adding indexes to make the time shorter but nothing helps...
any Ideas?
PS
the view and union are my idea but any other creative idea would be perfect!
bring it on!
thanks!
I don't know the best way to title this question but am trying to accomplish the following goal:
When a client logs into their profile, they are presented with a link to download data from an existing database in CSV format. The process works, however, I would like for this data to be 'fresh' each time they click the link so my plan was - once a user has clicked the link and downloaded the CSV file, the database table would 'erase' all of its data and start fresh (be empty) until the next set of data populated it.
My EXISTING CSV creation code:
<?php
$host = 'localhost';
$user = 'username';
$pass = 'password';
$db = 'database';
$table = 'tablename';
$file = 'export';
$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");
$result = mysql_query("SHOW COLUMNS FROM ".$table."");
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$csv_output .= $row['Field'].", ";
$i++;
}
}
$csv_output .= "\n";
$values = mysql_query("SELECT * FROM ".$table."");
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= '"'.$rowr[$j].'",';
}
$csv_output .= "\n";
}
$filename = $file."_".date("Y-m-d",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;
?>
any ideas?
Hi
I have code where I connected to the database like so:
$db = new mysqli("localhost", "user", "pass", "company");
Now when I query the database like so:
//query calls to a stored procedure 'user_info'
$result = $db->query("CALL user_info('$instruc', 'c_register', '$eml', '$pass', '')");
//I use the $result
This query works well. Now when I try and free that result like so:
$result->free();
or
$result->close();
It seems like it doesn't do anything because $result is still set. When I try to run another query it gives me this error:
Fatal error: Call to a member function fetch_array() on a non-object in...
For me to run this other query I have to close the db conection and connect again, then it will work. I want to know if there is a way I could run the other query without having to disconnect and reconnect to the database.
thanks in advance.
There are two tables:
Products
ID (Primary Key),
ProductName
PlannedByMonths
ProductID (Primary Key) (Link to the Products table many-to-one),
MonthNumber (Primary Key),
QtytoProduce,
How to write SELECT statement to retrieve results in the following format?
ProductName, QtytoProduceMonth1, QtytoProduceMonth2, QtytoProduceMonth3, QtytoProduceMonth4, QtytoProduceMonth5, QtytoProduceMonth6, QtytoProduceMonth7, QtytoProduceMonth8, QtytoProduceMonth9, QtytoProduceMonth10, QtytoProduceMonth11, QtytoProduceMonth12
Thank you.
Say you have a user table and an order table which references user (user has_many orders) and contains an item count field.
How could you efficiently ask "how many uses ordered how many items?"
That is, to generate something along the lines of:
Number of users | sum of items
-------------------------------
5 users | 1 item
4 users | 5 items
1 user | 7 items
Thanks in advance.
i have below table
it_id item_id item_name
1 ite_1 shirt
2 ite_10 pant
3 ite_11 socks
4 ite_12 shoes
5 ite_13 belt
now i need to change item_id with with ite_(value of it_id of that row)
means if it_id=x then item_id should be ite_x and so on...
what will b sql query for that??
I'm trying to get the YEARWEEK function to see Sunday as the 1st day of the week.
An example date is: Sunday 1st Mar 2009
Here is my sql
SELECT YEARWEEK('2009-03-01')
and the result is
- 200909
Which is week 9. I believe it is telling me this is week 9 because it sees the sunday as the last day of the previous week.
How would I get this function to see sunday as the 1st day of the week and therefore return as week 10?
I have my own server (with root access).
I need statistics of users who visit my website etc etc...
I have looked at an app called Webalyzer...
Is this a good choice?
I run apache2 on a Ubuntu 9 system...
If you know of any good statistics apps for servers please let me know.
And a follow-up question: All statistics are saved in log-files right? So how large would these log-files become then? Possibility to split them would be good, dont know if this is possible with Webalyzer though...
I have a database with details of daily sales.
To query a database, I have a form in a view with parameters that will query as date of admission, client and others.
The result is shown in another view with the daily details of income, and below is a summary of the article do all entered.
The summary I wish to transfer to another view, try to view :: composer but only transfer the empty query (I saw it with debug bar). Just appeared an empty view.
How I can transfer data from the database without the latter view is empty?
The second html view is totaly diferent , only the data is the same.
So, I have three tables with the following rows: Customers (Customer_id and Name), Orders (Customer_id, Product_id, Quantity) and Products (Price).
How do I write a query which shows all customers who spent more than 1000$? Do I have to join the tables?
Hi
I have asked this question before in this forum and they told me that it will retun an empty result set,I want to know that if I set the column with null values it will retun an empty result set?also the ANSI_NULLS is OFF ,thanks
SELECT 'A' FROM T WHERE A = NULL;
Hi,
is it possible to use date_sub like this ?
$dt = date("Y-m-d h:i:s");
$query = "INSERT INTO `table` (`date`) VALUES ('DATE_SUB('$dt', INTERVAL 15 DAY)')";
$result = MYSQL_QUERY($query);
Thanks