This question already has answers here:
How to join two tables mysql?
(4 answers)
Closed 5 years ago.
I have two table in mysql database. Database name frschool. First table name 'profile' fields id, invoice,name and second table name is 'exam' fields id, invoice, obt.mark.
Now how i join the tables for showing data in a one page .
If you want to join 'profile' table with 'exam' table you need to have in 'exam' table also the field idProfile or some field to make a connection between the 2 tables
Related
This question already has answers here:
MySQL, update multiple tables with one query
(7 answers)
Closed 1 year ago.
Respected Member
my first table company has following fields
com_id
p_id
p_name
my second table users has following fields
p_id
p_name
role_def
com_id
Question
I want to update multiple record on both tables with below query as example.
Please guide as it is not being working
UPDATE company,
users
SET company.p_name='Javeria Rauf',
users.p_name='Javeria Rauf',
users.role_def='Admin'
WHERE company.p_id=9
OR users.p_id=9
Just use two separate update statement as below:
To update company:
UPDATE company SET company.p_name = 'Javeria Rauf' WHERE company.p_id = 9 ;
To update users:
UPDATE users SET users.p_name = 'Javeria Rauf', users.role_def='Admin' WHERE users.p_id = 9 ;
This question already has answers here:
Sum Two Columns in Two Mysql Tables
(2 answers)
MySQL SUM multiple columns
(1 answer)
Closed 4 years ago.
So my question is how to SUM two columns in a SELECT query in MySQL.Here is the code I have written:
$qry = "SELECT supplier,
SUM(pay) as paid,
SUM(remaining) as remain
FROM managment
WHERE supplier = '".$_GET['ssupplier']."'";
But it only plus the column named remaining but not the pay columns.I have 2 pay columns with two values (10 and 50) but after SUM the column I am getting 1050 instead 60.Kindly take a look and help me with this problem.I want this in one table, not two tables
Thanks
This question already has answers here:
How to resolve ambiguous column names when retrieving results?
(11 answers)
Closed 2 years ago.
SELECT *
FROM companies
LEFT JOIN (ownership_reseller_to_company, users)
ON (users.ID=ownership_reseller_to_company.RESELLER_ID AND ownership_reseller_to_company.COMPANY_ID=companies.ID)
WHERE companies.NAME LIKE '%".$search_parm."%' AND users.ID='".$_USERID."'
My issue is I have NAME under companies and NAME under users but when I use $row['NAME']; I get the NAME under users. Is there a way to get the one under companies? I have tried $row['companies.NAME'] but with no success.
You need to use alias because column name is same in both table.
Example:
SELECT companies.name as cName, users.name as uName FROM companies .......
Than use like:
$row['cName'] // company name
$row['uName'] // user name
if you are using PDO you can:
$pdo->setAttribute(PDO::ATTR_FETCH_TABLE_NAMES, 1);
from the docs (http://www.php.net/manual/en/pdo.constants.php):
Prepend the containing table name to each column name returned in the result set. The table name and column name are separated by a decimal (.) character. Support of this attribute is at the driver level; it may not be supported by your driver.
This question already has answers here:
How to store day to day records from a mysql table to another?
(2 answers)
Closed 8 years ago.
is it possible to move one table column data to another column data after 1 or 2 days i mean like we have one table which is called table1 another table is table2 table1 have some data like name contact postal address then how to move all of data from table1 selected row to table2 after a period i mean one or two and when table1 data have move to table2 it will be delete from table1 .
in more details like we insert data into table1 like entry_day column using now() we get current date is there any option to after 1 days or 2 days the data will delete from tbl1 and insert into tbl2
$q= "INSERT INTO table1 (name,contact,postal,entrydate) values ('".$row[0]."','".$row[1]."','".$row[3]."',now())";
Just create a MySQL event to handle this based on the entrydate. Its quite easy and a quick google search will turn up plenty of information on how to create them.
This question already has an answer here:
Add a new column in all mysql tables
(1 answer)
Closed 9 years ago.
I want to add a common column in all tables in a database
For example:
I want to insert the column TENANT_ID in all tables in database
How can i do that.
You use the ALTER TABLE SQL command as in:
ALTER TABLE table_name
ADD column_name datatype
If you have multiple tables you'll need to apply this to each table in succession.
More here: http://www.w3schools.com/sql/sql_alter.asp
yes you can add it
if you have list of table in array
$column_name = 'TENANT_ID';
$size = '';
foreach($all_table_name as $each_table_name) {
mysql_query("ALTER TABLE {$each_table_name} ADD {$column_name} VARBINARY({$size})");
}
above code i just skilton you have to set accourding to your code.