更改表信息

时间:2016-10-08 12:14:32

标签: mysql sql

我有三张桌子:

表1 :(消费者)

# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost gat.local www.gat.local site.local www.site.local shop.local www.shop.local

表2 :( ConsumerLocation)

UserName   | FirstName | LastName
'Magika12'   'Ronald'    'Ludwig'

表3 :(位置)

UserName |  LocationID
'Magika12'  13234

我想将LocationID | StreetNumber | StreetName | Suburb | City | Postalcode 13234 13 Baker Street Melton Brisbane 4242 的地址改为:

Magika12

新表格如下:

"124 Braelands Crescent, Albion, Melbourne, 9999"

我尝试过这样的事情:

LocationID | StreetNumber | StreetName |        Suburb | City |    Postal code
13234        124            Braelands Crescent  Albion   Melbourne 9999

我知道这不正确,但我不知道如何将所有表连接在一起以更新UPDATE L1 SET L1.StreetNumber = 124, L1.StreetName = 'Braelands Crescent', L1.Suburb = 'Albion' , L1.City = 'Melbourne', L1.Postalcode = 9999 FROM Location L1 INNER JOIN ConsumerLocation WHERE ConsumerLocation.UserName = 'Magika' 的地址。我已将Magika12的主键UserNameConsumer的主外键设为ConsumerLocationLocationId Location的主键和Consumer Location的主外键。array_search(key_value,array)

任何帮助将不胜感激

3 个答案:

答案 0 :(得分:2)

你错过了DateTime back =DateTime.ParseExact("yyyy-MM-dd",row.Cells[9].Value, CultureInfo.InvariantCulture); Txtreqshipdate.Text = back; 陈述的条件。应该是这样的:

join

答案 1 :(得分:1)

您的加入需要 url = 'https://upload.wikimedia.org/wikipedia/commons/b/be/Random_pyramids.jpg'; 条件...试试这个。

ON

如果 INNER JOIN ConsumerLocation ON Location.LocationId = ConsumerLocation.LocationId 没有任何JOIN条件,则会在您加入的表格中获得所有可能的行组合。那可能是很多行。

答案 2 :(得分:1)

SELECT notes.project_id, notes.title, notes.description 
FROM notes, project_members 
WHERE notes.title LIKE '%second%' OR notes.description LIKE  '%second%'
WHERE notes.project_id = project_members.project_id AND project_members.user_id = '7'

如果您有多个与相同用户名相关的位置条目,请向WHERE子句添加LocationId:

UPDATE 
    Location L1 
    JOIN ConsumerLocation CL ON CL.LocationID = L1.LocationID
SET 
    L1.StreetNumber = 124,
    L1.StreetName = 'Braelands Crescent',
    L1.Suburb = 'Albion' ,
    L1.City = 'Melbourne',
    L1.Postalcode = 9999
WHERE CL.UserName = 'Magika12';