I have a table that looks like this:
|StreetName NR| NR |
|Teststreet 34| 34 |
How can i delete only the number in Streetname when it is the same in NR??
I have three update statements to be executed in PHP, i am getting the values of all these as return parameters. How to execute each statement independely and finally show the end user the result that it has been successfully updated.
<?php
public function name($parameter1,$parameter2.... $parametern) {
$records=array();
$sql="";
$sql2="";
$sql3="";
$result=mysql_query($sql);
//return $result;
if(!$result){throw new Exception(mysql_error());}
if(mysql_num_rows($result)==0){return $records;}
while($row=mysql_fetch_assoc($result)){$records[]=$row;}
return $records;
}
?>
Then how finally we can get the result in my row object.
Hello,
I am after an SQL command to find units with no categories. Here are the tables:
Unit
id name
UnitCategory
id name
UnitCategoryIndex
id categoryid unitid
Thanks!
| random_code | varchar(200) | YES | UNI | NULL | |
MyTable.objects.filter(random_code = None)
Is this correct? Will this SELECT where there is no random code set? Above is my table.
I'm trying to update a table to remove all but the first instance of a group. Basically, I have a table with vehicle data related to an insurance policy. Each policy should only have one power_unit. Everything else should be a towed unit. Unfortunately, a bug has been duplicating power units, and now I need to clean this up. There are ~10k records in the database, and ~4k of them have doubled up power units.
The important bits of my table (call it test1 for now) are:
+------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------+------+-----+---------+----------------+
| id | int(10) | NO | PRI | NULL | auto_increment |
| policy_id | int(10) | NO | | NULL | |
| power_unit | int(1) | NO | | 0 | |
+------------+---------+------+-----+---------+----------------+
And some sample data:
+----+-----------+------------+
| id | policy_id | power_unit |
+----+-----------+------------+
| 1 | 1 | 1 |
| 2 | 1 | 1 |
| 3 | 1 | 1 |
| 4 | 2 | 1 |
| 5 | 2 | 1 |
| 6 | 2 | 1 |
| 7 | 4 | 1 |
| 8 | 4 | 1 |
| 9 | 4 | 1 |
| 10 | 5 | 1 |
| 11 | 5 | 1 |
| 12 | 6 | 1 |
+----+-----------+------------+
Basically I'd like to end up where policy_id 1 has only one power_unit=1. Same for policy_id 2, 3, 4, etc. For policy_id 6, nothing should change (there is only one entry, and it is a power_unit already).
I don't know if this is possible, but it was an intriguing problem for me, so I thought you guys might find it the same.
hello, im trying to delete a foreign key with the following syntax (5.0.45-community-nt):
alter table [table] drop foreign key [fk_name]
but I'm getting the folling error:
The table '#sql-5f8_9c' is full – 99543 ms
any ideas?
thanks!
"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 a table employee(id,dept_id,salary,hire_date,job_id) . the following query i have to execute.
Show all the employee who were hired on the day of the week on which least no of employee were hired.
i have done the query, but am not able to get the least. please check if am correct.
select id, WEEKDAY(hire_date)+1 as days,count(WEEKDAY(hire_date)+1) as count
from test.employee group by days
Hey guys
Im trying to develop an advance consumer website using php and I stuck somewhere while trying to get the data with submitting to another page. All I want to do is to get the checkbox values which are stored in an array and checked by user. I urgently need your help please here is the code:
$sql2="SELECT * FROM alinanfis WHERE alinanfis.fis_id='".$fis."'" ;
$resultFis=mysql_query($sql2);
if(mysql_num_rows($resultFis)>0)
{
print "<form method='POST' action='deletionResult.php'>";
print "<table>";
print "<tr>";
print "<th style='background: transparent;'></th>";
print "<th>Fis No</th>";
print "<th>isim</th>";
print "<th>soyisim</th>";
print "<th >Tarih</th>";
print "<th>Fis Tipi</th>";
print "<th>Nerede</th>";
print "<th>Litre</th>";
print "<th>Tutar</th>";
print "</tr>";
while($rowAlinan=mysql_fetch_array($resultFis))
{
$sqlFisTipi="SELECT * FROM atype WHERE a_id='".$rowAlinan['a_id']."'" ;
$resultFisTipi=mysql_query($sqlFisTipi);
$rowFisTipi=mysql_fetch_array($resultFisTipi);
$sqlNerede="SELECT * FROM isyeri WHERE i_id='".$rowAlinan['nerde']."'" ;
$resultNerede=mysql_query($sqlNerede);
$rowNerede=mysql_fetch_array($resultNerede);
$sqlMID="SELECT * FROM musteri WHERE m_id='".$rowAlinan['m_id']."'" ;
$resultMID1=mysql_query($sqlMID);
$rowMID1=mysql_fetch_array($resultMID1);
print "<tr>";
print "<td><input name='checkBox[]' type='checkbox' value='".$rowAlinan['fis_id']."' />
php</td>";
print "<td>".$rowAlinan['fis_id']."</td>";
print "<td>".$rowMID1['m_name']."</td>";
print "<td>".$rowMID1['m_lastName']."</td>";
print "<td>".$rowAlinan['alinan_tarih']."</td>";
print "<td>".$rowFisTipi['a_name']."</td>";
print "<td>".$rowNerede['i_name']."</td>";
print "<td>".$rowAlinan['litre']."</td>";
print "<td>".$rowAlinan['tutar']."</td>";
print "</tr>";
}
print '<div class="form_settings">';
print "<input class='submit' type='submit' name= 'send' value='Send'>";
/
print '</div>';
print "</table>";
print "</form>";
}//end of if(num_rows>0)
else
echo '*no such receipt found!!';
mysql_close($con);
I have a huge table that is mainly used for backup and administrative purposes. The only records that matters is the last inserted record.
On every hit to order by time inserted is just too slow. I want keep a separate table with the last inserted id.
In PHP I now insert, get last inserted id, and update the other table.
Is there a more efficient way to do this.
I have 3 tables, with 3 fields all the same. I basically want to select information from each table
For example:
userid = 1
I want to select data from all 3 tables, where userid = 1
I am currently using:
SELECT r.*,
p.*,
l.*
FROM random r
LEFT JOIN pandom p ON r.userid = p.userid
LEFT JOIN landom l ON l.userid = r.userid
WHERE r.userid = '1'
LIMIT 0, 30
But it doesn't seem to work.
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
I'm working on a sparse matrix class that needs to use an array of LinkedLists to store the values of a matrix. Each element of the array (i.e. each LinkedList) represents a row of the matrix. And, each element in the LinkedLists represents a column and the stored value.
In my class, I have a declaration of the array as:
private LinkedList<IntegerNode>[] myMatrix;
And, in my constructor for the SparseMatrix, I try to define:
myMatrix = new LinkedList<IntegerNode>[numRows];
The error I end up getting is "Cannot create a generic array of LinkedList<IntegerNode>." So, I have two issues with this, 1) What am I doing wrong, and 2) Why is the type acceptable in the declaration for the array if it can't be created?
Edit: IntegerNode is a class that I have created. And, all of my class files are packaged together.
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'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
I have problem in asp.ne Mvc with multiple model in one view on create and update
I 'm work on exams system
class Questions and class Answers
Question is aparent class and Answers is a child class
[Bind(exclude("id"))]
class Quesions
{
public string question{get; set;}
public Datetime Timepostquestion{get; set;}
}
[Bind(exclude("id"))]
class Answers
{
public string answer{get; set;}
public Datetime Timepostanswer{get; set;}
public questionId {get; set;}
}
in a view I use two classes how to use classes in insert and update
what a way which I have to solve my problem
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
in plain english can you explain to me what happens here:
rs.Open "batchinfo", oConn, adOpenKeyset, adLockOptimistic, adCmdTable
what i need to do is to be able to insert values into a table called batchinfo. would this be the best way to do an OPEN?
the only thing i would be doing is inserting values.