Sqlite Distinct Query From -To、To --From

user943716

次のデータがあります:
me = my_userid;

表:メッセージ

message_id | message_from | message_to
1 | 私| ユーザー
2 | ユーザー|

クエリを実行すると、2つの行が表示されます(SELECT DISTINCT message_from、message_to FROM Message WHERE message_from = '"+ me +"' OR message_to = '"+ me +"' ");

私のIDがfrom(送信時)またはTO(他のユーザーが私にメッセージを送信したとき)にある可能性があるため、ORを使用します

-これは2行を返しますが、-に切り替えると同じIDを取得するため、1行を返します。では、クエリでこれをどのように行うことができますか。ありがとう

ゴードン・リノフ

min()およびmax()スカラー関数として使用できます

select distinct min(message_from, message_to) as m1, max(message_from, message_to) as m2
from message
where message_from ='"+me+"' OR message_to ='"+me+"'"

これらは、他のデータベースleast()同等greatest()です。

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to filter out from count distinct query

分類Dev

SQLite query to get data from multiple tables

分類Dev

Query for getting distinct pairs from a single column with an added constraint

分類Dev

Retrieve Distinct Values From NotePad Elements

分類Dev

map from observable array to distinct string array

分類Dev

Perl: Extract distinct patterns from a string

分類Dev

Add extra row from distinct in select

分類Dev

Select fields from table with DISTINCT field

分類Dev

Select multiple fields from columns with distinct and limit

分類Dev

Choose k distinct and increasing index from n

分類Dev

$ sql = "SELECT DISTINCT sem from $ _SESSION ['ye']";

分類Dev

SQLite COUNT JOIN DISTINCT

分類Dev

From Sqlite3 to Sqlalchemy

分類Dev

Store String from SQLite to NSMutableArray

分類Dev

Export database from SQLite to MongoDB

分類Dev

No results from SQL Query

分類Dev

No results from SQL Query

分類Dev

Oracle Query Update From

分類Dev

SQL Distinct Group By Query

分類Dev

LINQ query Distinct issue

分類Dev

My MANIFEST.in content installed to distinct location from rest of package

分類Dev

MySQL - count distinct values from one column based on another column

分類Dev

How to get distinct values from an array of fetch API output

分類Dev

Select distinct values from a column based on highest value in another column

分類Dev

Distinct value from array looking field type that is a string?

分類Dev

Distinct values from array based on a part of the string in JS

分類Dev

pyspark: what is the best way to select n distinct IDs from a dataset

分類Dev

How to get distinct values from an array in mongoDB and group them by ID

分類Dev

How many distinct combinations can be made from a complex group?

Related 関連記事

  1. 1

    How to filter out from count distinct query

  2. 2

    SQLite query to get data from multiple tables

  3. 3

    Query for getting distinct pairs from a single column with an added constraint

  4. 4

    Retrieve Distinct Values From NotePad Elements

  5. 5

    map from observable array to distinct string array

  6. 6

    Perl: Extract distinct patterns from a string

  7. 7

    Add extra row from distinct in select

  8. 8

    Select fields from table with DISTINCT field

  9. 9

    Select multiple fields from columns with distinct and limit

  10. 10

    Choose k distinct and increasing index from n

  11. 11

    $ sql = "SELECT DISTINCT sem from $ _SESSION ['ye']";

  12. 12

    SQLite COUNT JOIN DISTINCT

  13. 13

    From Sqlite3 to Sqlalchemy

  14. 14

    Store String from SQLite to NSMutableArray

  15. 15

    Export database from SQLite to MongoDB

  16. 16

    No results from SQL Query

  17. 17

    No results from SQL Query

  18. 18

    Oracle Query Update From

  19. 19

    SQL Distinct Group By Query

  20. 20

    LINQ query Distinct issue

  21. 21

    My MANIFEST.in content installed to distinct location from rest of package

  22. 22

    MySQL - count distinct values from one column based on another column

  23. 23

    How to get distinct values from an array of fetch API output

  24. 24

    Select distinct values from a column based on highest value in another column

  25. 25

    Distinct value from array looking field type that is a string?

  26. 26

    Distinct values from array based on a part of the string in JS

  27. 27

    pyspark: what is the best way to select n distinct IDs from a dataset

  28. 28

    How to get distinct values from an array in mongoDB and group them by ID

  29. 29

    How many distinct combinations can be made from a complex group?

ホットタグ

アーカイブ