473,320 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

sombody help me with my sql query......!

I have this table:
message
Expand|Select|Wrap|Line Numbers
  1. --------+-----------+-------------+----------+-------+-----------+
  2. msg_id  + sender_id  + recepient_id +  content  + read  + time_sent  +
  3. --------+-----------+-------------+----------+-------+-----------+
  4.  auto            1                2              hello!           0        4pm ---------the value of this 
  5.  incre-          2                1                hi!             0        5pm              field is TIMEDATE
  6.  ment           3                1              cute!           0         10am            this is just a sample
  7.                   1               100            how r u         0         5pm
  8.                   4                 1              lol!               0         6am
  9.                   1                  4             c u!             0          3am
  10.                   5                  1             hehe!           0          1am
  11. -------------------------------------------------------
  12.  
Im so stuck on this one.
for example the user is 1:
how can I query all the messages send and receive by ID = 1,
for example I received message from ID=2 and then ID=1 reply..
how can I get the last message sent or receive by ID=1.
in this example the sample output shoul look lyk this with conversation
with ID=2:
output: login as user 1
-----------
Message:
Conversation with: 2 "hi!"
-----------
on the output sample above "hi!" was display because this is the latest message since "hello!"
was sent 4pm while "hi!" was 5pm
-----------

so the whole output would be: ORDER BY message_id

Message:
Conversation with: 2 "hi!"
Conversation with: 3 "hehe"
Conversation with: 100 "how r u"
Conversation with: 4 "lol!"
Conversation with: 5 "lol!"
-------------------------------------------------------------------------------------------------------------
I come up with this query but how can I ORDER it by message_id:
Expand|Select|Wrap|Line Numbers
  1. SELECT sender_id as sid FROM dating_message
  2. WHERE recepient_id = 1 and
  3. sender_id IN (SELECT sender_id FROM dating_message WHERE recepient_id = 1 )
  4. GROUP BY sid
  5. UNION
  6. SELECT recepient_id as sid FROM dating_message
  7. WHERE sender_id = 1 and
  8. recepient_id IN (SELECT recepient_id FROM dating_message WHERE sender_id = 1 )
  9. GROUP BY sid
  10.  
It is good practise and required by the posting rules to enclose code and/or table data within code or php tags. That makes it a lot easier to read.
So read the Posting Guidelines before you continue posting here.

moderator
Feb 28 '07 #1
1 1077
ronverdonk
4,258 Expert 4TB
For all entries for ID=1, sorted by time (latest on top) use a statement like this one

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM table WHERE sender_id=1 OR recepient_id=1 ORDER BY time_sent DESC;
Ronald :cool:
Feb 28 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
3
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says...
4
by: Diamondback | last post by:
I have two tables, WIDGETS and VERSIONS. The WIDGETS table has descriptive information about the widgets while the VERSIONS table contains IDs relating to different iterations of those widgets...
14
by: Dave Thomas | last post by:
If I have a table set up like this: Name | VARCHAR Email | VARCHAR Age | TINYINT | NULL (Default: NULL) And I want the user to enter his or her name, email, and age - but AGE is optional. ...
2
by: sumi | last post by:
I am very new to python , I have small query could some one help me. every time I get a new load i need to do few things like creating some dir, changing some file contents and moving some files ,...
1
by: hemant kamble | last post by:
Hi all, I am hemant , I am new for VB. Can sombody help to access serial port in VB on windows XP. I am trying with Ports.bas but ididn't get success kindly anybody give code for access serial...
0
by: hemant kamble | last post by:
Hi all, I am hemant , I am new for VB. Can sombody help to access serial port in VB on windows XP. I am trying with Ports.bas but ididn't get success kindly anybody give code for access serial...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.