两个表之间的链接具有相同的值,结果将在链接时重复

时间:2017-02-22 05:44:40

标签: sql

enter image description here

我使用这些代码SELECT id , date FROM table1 UNION ALL SELECT id ,k1'
FROM ork9 group by id ORDER BY k1,k3 ASC
但重新编码重复

2 个答案:

答案 0 :(得分:2)

union将不是一个好的选择试试这个

select table2.id,table1.date from table2 
left join table1 on table1.id = table2.id

这将返回您的预期结果

答案 1 :(得分:0)

<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'My_API_KEY' );
$registrationIds = array( TOKENS );
// prep the bundle
$msg = array
(
    'body'  => "abc",
    'title'     => "Hello from Api",
    'vibrate'   => 1,
    'sound'     => 1,
);

$fields = array
(
    'registration_ids'  => $registrationIds,
    'notification'          => $msg
);

$headers = array
(
    'Authorization: key=' . API_ACCESS_KEY,
    'Content-Type: application/json'
);

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;
?>

这将连接两个表并从table2中获取所有记录,并且只从table1

中获取日期