首页 \ 问答 \ 如何从两个不同的表中获取数据(没有重复记录)?(How to fetch data ( without duplicates records ) from two different tables ? where both tables have common value)

如何从两个不同的表中获取数据(没有重复记录)?(How to fetch data ( without duplicates records ) from two different tables ? where both tables have common value)

表格1

newpancard

id | name | cardno | status |
-----------------------------
1  | name1| 909099 | done   |
2  | name2| 800099 | done   |
3  | name3| 965099 | pending|

表2

oldpancard

id | name | cardno | status |
-----------------------------
1  | name4| 111119 | done   |
2  | name5| 323239 | done   |
3  | name6| 734349 | pending|
4  | name7| 609099 | done   |

我们可以从两个表中获取status = done的两个表获取数据吗?

我正在尝试以下查询,但批量获取重复数据。

SELECT tb1.*, tb2.* 
FROM `newpancard` tb1 
JOIN `oldpancard` tb2 
  ON tb1.status = tb2.status

请纠正我。 谢谢


Table 1

newpancard

id | name | cardno | status |
-----------------------------
1  | name1| 909099 | done   |
2  | name2| 800099 | done   |
3  | name3| 965099 | pending|

Table 2

oldpancard

id | name | cardno | status |
-----------------------------
1  | name4| 111119 | done   |
2  | name5| 323239 | done   |
3  | name6| 734349 | pending|
4  | name7| 609099 | done   |

can we get fetch data from both tables where status = done in both tables?

I am trying the following query but getting duplicates data in bulk.

SELECT tb1.*, tb2.* 
FROM `newpancard` tb1 
JOIN `oldpancard` tb2 
  ON tb1.status = tb2.status

please correct me. Thanks


原文:https://stackoverflow.com/questions/51694065
更新时间:2023-09-24 19:09

最满意答案

解释究竟是什么让你错误的方法失败是次要的:主要的是修复方法。

对于此通信模式,您应该使用所有HTTP作业发送其状态的actor ,而不是async-awaitlaunch 。 这将自动处理所有并发问题。

以下是一些示例代码,取自您在评论中提供的链接,并根据您的用例进行了调整。 而不是某些第三方要求它获取计数器值并使用它更新GUI,actor在UI上下文中运行并更新GUI本身:

import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.channels.*
import kotlin.system.*
import kotlin.coroutines.experimental.*

object IncCounter

fun counterActor() = actor<IncCounter>(UI) {
    var counter = 0
    for (msg in channel) {
        updateView(++counter)
    }
}

fun main(args: Array<String>) = runBlocking {
    val counter = counterActor()
    massiveRun(CommonPool) {
        counter.send(IncCounter)
    }
    counter.close()
    println("View state: $viewState")
}


// Everything below is mock code that supports the example
// code above:

val UI = newSingleThreadContext("UI")

fun updateView(newVal: Int) {
    viewState = newVal
}

var viewState = 0

suspend fun massiveRun(context: CoroutineContext, action: suspend () -> Unit) {
    val numCoroutines = 1000
    val repeatActionCount = 1000
    val time = measureTimeMillis {
        val jobs = List(numCoroutines) {
            launch(context) {
                repeat(repeatActionCount) { action() }
            }
        }
        jobs.forEach { it.join() }
    }
    println("Completed ${numCoroutines * repeatActionCount} actions in $time ms")
}

运行它打印

Completed 1000000 actions in 2189 ms
View state: 1000000

The explanation what exactly makes your wrong approach fail is secondary: the primary thing is fixing the approach.

Instead of async-await or launch, for this communication pattern you should instead have an actor to which all the HTTP jobs send their status. This will automatically handle all your concurrency issues.

Here's some sample code, taken from the link you provided in the comment and adapted to your use case. Instead of some third party asking it for the counter value and updating the GUI with it, the actor runs in the UI context and updates the GUI itself:

import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.channels.*
import kotlin.system.*
import kotlin.coroutines.experimental.*

object IncCounter

fun counterActor() = actor<IncCounter>(UI) {
    var counter = 0
    for (msg in channel) {
        updateView(++counter)
    }
}

fun main(args: Array<String>) = runBlocking {
    val counter = counterActor()
    massiveRun(CommonPool) {
        counter.send(IncCounter)
    }
    counter.close()
    println("View state: $viewState")
}


// Everything below is mock code that supports the example
// code above:

val UI = newSingleThreadContext("UI")

fun updateView(newVal: Int) {
    viewState = newVal
}

var viewState = 0

suspend fun massiveRun(context: CoroutineContext, action: suspend () -> Unit) {
    val numCoroutines = 1000
    val repeatActionCount = 1000
    val time = measureTimeMillis {
        val jobs = List(numCoroutines) {
            launch(context) {
                repeat(repeatActionCount) { action() }
            }
        }
        jobs.forEach { it.join() }
    }
    println("Completed ${numCoroutines * repeatActionCount} actions in $time ms")
}

Running it prints

Completed 1000000 actions in 2189 ms
View state: 1000000

相关问答

更多
  • 解释究竟是什么让你错误的方法失败是次要的:主要的是修复方法。 对于此通信模式,您应该使用所有HTTP作业发送其状态的actor ,而不是async-await或launch 。 这将自动处理所有并发问题。 以下是一些示例代码,取自您在评论中提供的链接,并根据您的用例进行了调整。 而不是某些第三方要求它获取计数器值并使用它更新GUI,actor在UI上下文中运行并更新GUI本身: import kotlinx.coroutines.experimental.* import kotlinx.coroutine ...
  • 假设您已将kotlin插件应用于项目: import org.jetbrains.kotlin.gradle.dsl.Coroutines plugins { kotlin("jvm") } kotlin { // type is KotlinJvmProjectExtension experimental.coroutines = Coroutines.ENABLE } 这适用于Gradle 4.4.1和4.5-rc-1,我之前也应该使用版本。 如果你使用buildscript而不是插件引入 ...
  • num++由两个操作组成: tmp = num + 1和num = tmp 。 在处理像你的例子这样的多线程时,有些操作可能会覆盖另一个线程的结果,导致像你的例子一样的情况。 如果你想了解更多,研究“竞争条件”,最终结果取决于两个独立过程之间的“竞争”。 num++ consists of two operations: tmp = num + 1 and num = tmp. When dealing with multithreading like your example there are case ...
  • 如果你看一下CommonPool的实现,你会发现它正在使用java.util.concurrent.ForkJoinPool或一个具有以下大小的线程池: (Runtime.getRuntime().availableProcessors() - 1).coerceAtLeast(1) 有4可用处理器,这将导致3 ,这就是为什么你看到3个工作线程的原因。 ForkJoinPool -size可以确定如下(将是相同的): ForkJoinPool.commonPool().parallelism If yo ...
  • 从kotlinx.coroutines 0.19.1开始,协程为Spring Framework 5中使用的Reactor Core 3.1提供支持。 作为spring-kotlin-coroutine社区项目的一个实验,Spring Framework 5协程支持目前正在进行中。 这种支持尚未计划在本地进行Spring Framework 5集成,但是您可以遵循并最终投票支持SPR-15413 。 有关Flux和Mono如何适应Coroutines世界的问题,请参阅此评论 。 请记住,协同程序仍然是实验性 ...
  • 您应该从另一端开始:启动基于UI的协同程序,从中将大量操作交给外部池。 选择的工具是withContext() : override fun loginButtonPressed(email: String, password: String) { view.showSignInProgressAnimation() launch(UI) { try { val user = withContext(CommonPool) { ...
  • 如果您原谅我,我会从第一个链接中的Deferred课程文档中引用第一句话开始: 延期价值是一个不可阻挡的可取消未来。 事实上,延期是未来或承诺的代名词( 参见本维基百科文章 )。 Deferred类是kotlinx-coroutines项目的一部分,为Kotlin协同程序提供了库支持。 开始学习更多关于它的推荐方法是阅读本指南 。 I would start, if you excuse me, by quoting the first sentence from the documentation on ...
  • withTimeout { ... }旨在取消正在进行的超时操作,这只有在相关操作可以取消时才有可能。 它与future.get(timeout, unit)一起使用的原因是因为它只等待超时。 它实际上不会以任何方式取消或中止您的后台操作,该操作在超时后仍然继续执行。 如果你想模仿coroutines的类似行为,那么你应该等待超时,如下所示: val d = async { block() } // run the block code in background withTimeout(timeout, ...
  • 您可以手动保留您启动的Job对象列表,但您也可以使用现成的父子Job Hierarhy来管理和保持已启动作业的列表更容易。 因此,首先,您要定义对父作业的引用,而不是作业列表: val job = Job() 然后,每当你找到一个新的协程时,你就会成为这个工作的孩子 : fun startJob1() { launch(job) { // make it a child //do some work } } fun startJob1() { launch(job ...
  • 这个例子的重点是实现Eratosthenes的Sieve 。 换句话说,通过过滤掉由于它们的可分性而不能成为素数的数字来查找素数。 剩下的都是素数。 让我们看看我们有什么。 我现在要忽略所有的context变量,它只是让事情更容易讨论。 首先,我们有一个名为numbersFrom的函数,它只是从2开始的无限整数序列(在本例中)。 我们还有一个名为filter函数,它接收一个通道,以及一个可能是素数的数字。 查看返回类型,我们可以看到此函数返回一个新的生成器。 为了产生结果(在这种情况下为Int s),可以调 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)