政府立案,24小時全年無休!公司家庭搬遷、合約簽訂有保證 提供您平價又專業的搬家服務. | 裝璜拆除,店面拆除,地板拆除,廢棄物清運 服務有保證,安全高效率,客戶口碑肯定 |
[php] MySQL 兩個資料表 UPDATE |
房東:小蛙 發表時間:2011-08-25 | [檢舉] |
Let\'s say for example you have a product table which stores information about products and a productPrice table which has pricing information and you want to update the prices based on when the product was created (in the examples below you want to discount all your older stuff to 80% of the current price). In MySQL you can do this in one of two ways. The first is do do a join using commas, like so:
The second way is to use inner join syntax as shown below. This syntax is slightly more flexible as it means you can use left and right joins as well as inner joins, whereas the previous example is an implicit inner join.
Another example of doing this in MySQL but using a left join to flag all the products that do not have assocated entries in the productPrice table is as follows:
This isn\'t necessarily a very realistic example as you would be more likely to want to straight out delete the non-matching entries or use a select query instead to display them in a list for editing but it illustrates how it can be done. The article about how to delete records with MySQL using a cross join uses these examples to delete instead of update. Note that it\'s also possible in MySQL to update values in all the tables that are joined in the query. In this example we\'re doing the same query as in the first two examples but also updating the "dateUpdated" value in the product table.
|
廣利不動產-板橋在地生根最實在--新板特區指名度最高、值得您信賴的好房仲 完整房訊,房屋、店面熱門精選物件,廣利不動產 優質仲介,房屋租賃、買賣資訊透明,交易真安心! 廣利不動產-新板特區指名度最高、值得您信賴的好房仲 您的托付,廣利用心為您服務 |