The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How To: SELECT 1 or 2 rows depending on a DISTINCT single row
#1
Hello everyone.
I currently have a database called wall. If contains a record of a text post, OR a picture post, OR a picture and a text post. So there should be 1 of 3 outputs from my SELECT. But right now, my SELECT statement only returns one row at a time, which is fine if someone only posts a text post, or if someone only posts a picture post, but in the case that they post a picture AND text at the same time (the same td) then I need those 2 rows returned so I can process them TOGETHER.

My current SELECT statement: SELECT rowId, td, filename, userId, deleted FROM wall ORDER BY td DESC

The output from my current SELECT statement:

rowId td filename userId deleted

107 1556377561 ../users/wall/2019/04/1556377561.1218.txt 11 0
106 1556377561 ../users/wall/2019/04/1556377561.1218.png 11 0
105 1556377556 ../users/wall/2019/04/1556377556.0624.txt 11 0
104 1556377556 ../users/wall/2019/04/1556377556.0624.png 11 0
103 1556377530 ../users/wall/2019/04/1556377530.5411.txt 11 0
102 1556377522 ../users/wall/2019/04/1556377522.3709.txt 11 0
101 1556377393 ../users/wall/2019/04/1556377393.0412.txt 11 0
99 1556377380 ../users/wall/2019/04/1556377380.8744.png 11 0
100 1556377380 ../users/wall/2019/04/1556377380.8744.txt 11 0
98 1556375783 ../users/wall/2019/04/1556375783.454.txt 11 0
97 1556375751 ../users/wall/2019/04/1556375751.5567.txt 11 0
96 1556375751 ../users/wall/2019/04/1556375751.5567.png 11 0
95 1556345197 ../users/wall/2019/04/1556345197.4695.txt 1 0
94 1556345197 ../users/wall/2019/04/1556345197.4695.png 1 0
93 1556345018 ../users/wall/2019/04/1556345018.6357.txt 1 0
92 1556345018 ../users/wall/2019/04/1556345018.6357.png 1 0
91 1556345000 ../users/wall/2019/04/1556345000.6300.png 1 0

As you can see, the output returns a row containing either a row with a record of a text post, or a row containing a record of a picture post. This is good IF people only post a text post OR a picture post, but if they post a text AND a picture post, my current SELECT statement won't know because it only returns EITHER a text post OR a picture post, but it doesn't yet return the possibility of a text AND a picture post.

Output possibility 1) a single row that is a text post row

rowId td filename userId deleted
103 1556377530 ../users/wall/2019/04/1556377530.5411.txt 11 0
(I will display this as a text only post)

Output possibility 2) a single row that is a picture post row

rowId td filename userId deleted
91 1556345000 ../users/wall/2019/04/1556345000.6300.png 1 0
(I will display this as a picture posted without a text message associated with the picture)

Output possibility 3) 2 rows that contains both the text row and the picture row as a set

rowId td filename userId deleted
107 1556377561 ../users/wall/2019/04/1556377561.1218.txt 11 0
106 1556377561 ../users/wall/2019/04/1556377561.1218.png 11 0
(I will show this as a picture that goes with some associated text)

So I need a SELECT statement that returns either 1 row with a text post if there is not an associated picture post with that same td (time in seconds), or 1 row with a picture post if there is not an associated text post with that same td (time in seconds), or 2 rows with a text post AND a picture post with the same td (time in seconds). Then I can show EITHER the text post if there was no picture posted with the text, or a picture post if there was no text posted with it, or the text AND picture because they were posted at the same time as a set.

Any suggestions welcome.
  Reply


Messages In This Thread
How To: SELECT 1 or 2 rows depending on a DISTINCT single row - by Malatesa - 04-27-2019, 04:01 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)