如何在SQL中执行以下操作,访问

本文关键字:操作 访问 执行 SQL | 更新日期: 2023-09-27 18:07:13

我有以下查询

SELECT dictionaryEncryptedIndex, filelocation FROM  `DictionaryTable`
 WHERE  `dictionaryEncryptedWord` LIKE '0x0E6E'";

在c#中,我对上述查询的结果进行循环,对于每次循环迭代,我使用以下查询来获得最终结果:

SELECT * FROM  `MaskedIndexTable` 
 WHERE  `maskedIndexEncryptedIndex`
  LIKE '" + dictionaryEncryptedIndexFROMABOVEQUERY + "'
   AND `fileLocation` = '" + filelocationFROMABOVEQUERY + "'";

dictionaryEncryptedIndex和maskedIndexEncryptedIndex之间不是一对一的关系。

有没有人知道如何在一个SQL查询,可以在微软访问中使用上述?

我试过很多方法,比如:

SELECT  * from DictionaryTable, MaskedIndexTable
  WHERE MaskedIndexTable.maskedIndexEncryptedIndex = DictionaryTable.dictionaryEncryptedIndex 
    AND  MaskedIndexTable.fileLocation =DictionaryTable.fileLocation
    AND `dictionaryEncryptedWord` LIKE '0x0E6E' 

SELECT dictionaryEncryptedWord, DictionaryTable.filelocation
  FROM DictionaryTable
 INNER JOIN MaskedIndexTable
    ON (MaskedIndexTable.maskedIndexEncryptedIndex =DictionaryTable.dictionaryEncryptedIndex  )
 WHERE  `dictionaryEncryptedWord` LIKE '...' 

SELECT distinct *
  FROM MaskedIndexTable
 INNER JOIN DictionaryTable 
    ON (MaskedIndexTable.maskedIndexEncryptedIndex = DictionaryTable.dictionaryEncryptedIndex  )
 WHERE   MaskedIndexTable.Id IN  
(
    SELECT DictionaryTable.Id
      FROM  DictionaryTable
     WHERE  `dictionaryEncryptedWord` LIKE '..') 
   AND  `dictionaryEncryptedWord` LIKE '...'

,但他们似乎都没有产生正确的结果(结果我得到我的c#代码)

如何在SQL中执行以下操作,访问

如果您想在LIKE条件中使用通配符,则需要更改此设置。

首先在Access中创建一个类似于第一个查询的名为encryptedWordsQuery

的查询
SELECT DictionaryTable.dictionaryEncryptedIndex, DictionaryTable.fileLocation
FROM DictionaryTable
WHERE (((DictionaryTable.dictionaryEncryptedWord) Like "0x0E6E"));

在Access中创建查询,如下所示:

SELECT MaskedIndexTable.maskedIndex, MaskedIndexTable.maskedIndexEncryptedIndex, MaskedIndexTable.fileLocation
FROM MaskedIndexTable
WHERE Exists (SELECT * 
                FROM encryptedWordsQuery 
               WHERE MaskedIndexTable.maskedIndexEncryptedIndex = encryptedWordsQuery.dictionaryEncryptedIndex
                     AND MaskedIndexTable.fileLocation = encryptedWordsQuery.FileLocation);

我发现在Access中创建两个单独的查询比创建一个查询更容易。

我认为这应该是工作-如果你能够张贴样本数据,我们可以做一个SQLFiddle来演示它。

SELECT  dt.dictionaryEncryptedIndex, dt.filelocation 
FROM    DictionaryTable dt
    INNER JOIN MaskedIndexTable mit
        ON mit.fileLocation = dt.fileLocation 
            AND mit.maskedIndexEncryptedIndex = dt.dictionaryEncryptedIndex
WHERE   dt.dictionaryEncryptedWord LIKE '0x0E6E*'