0
SELECT t.dateline AS date,t.tid, t.subject, u.avatar,t.views, t.username, t.replies, u.profilepic, t.uid, p.thumbsup, t.firstpost, f.name, f.fid, p.message, a.updatetime, a.md5hash, a.uploadtime, a.aid, a.attachname, a.filename, a.thumbs, td.vidid, td.cat, td.portada
FROM ". TABLE_PREFIX ."threads t 
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=t.fid)
LEFT JOIN ".TABLE_PREFIX."xtattachments a ON (a.tid=t.tid)
LEFT JOIN ".TABLE_PREFIX."threadfields_data td ON (td.tid=t.tid)
LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=t.firstpost)
WHERE t.fid IN ($f4id) AND t.uid IN ($show_post_list)  

UNION ALL

SELECT th.dateline AS date, th.thumbsup, th.uid
FROM ". TABLE_PREFIX ."thumbspostrating th 


ORDER BY date DESC 
LIMIT ".(($page-1)*$perpage).", ".$perpage);

Example:

  1. Thread number one dateline: today
  2. Like number one dateline: yesterday 1:10pm
  3. Thread number two dateline: yesterday 1:09pm
  4. Like number two dateline: yesterday 1:08pm
  5. Like number three dateline: yesterday 1:07pm
  6. Thread number three dateline: yesterday 1:05pm

I don’t know why this doesn’t work? In ORDER BY <-- I need t.dateline and l.dateline in to one for do that example.

1222 - The used SELECT statements have a different number of columns

5
  • 1
    define: doesn't work? Commented May 4, 2014 at 17:58
  • is uid defined as a column here ?? Commented May 4, 2014 at 18:03
  • 1
    1222 - The used SELECT statements have a different number of columns Of course t.uid and th.uid Commented May 4, 2014 at 18:12
  • Are you having a laugh? You've completely changed the query and effectively the question. Commented May 4, 2014 at 20:12
  • This question appears to be off-topic because it changes each time you answer it. Commented May 4, 2014 at 20:15

2 Answers 2

1

You can try to do add as dateline to your select SELECT l.dateline as dateline , l.name, l.avatar.

That worked for me. If that does not work you can always do a select on your selects and then order that result it would read something like this

SELECT dateline, name, avatar FROM ( 
  SELECT t.dateline, t.name, u.avatar
  FROM ". TABLE_PREFIX ."threads t 
  LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)

  UNION ALL

  SELECT l.dateline, l.name, l.avatar
  FROM ". TABLE_PREFIX ."likes l 
  LEFT JOIN ".TABLE_PREFIX."treads t ON (t.uid=l.uid)
) as x
ORDER BY x.dateline DESC 
LIMIT 10;
Sign up to request clarification or add additional context in comments.

6 Comments

is uid a column here ??
It sends and error: 1222 - The used SELECT statements have a different number of columns
Well you changed the complete query i see but if i see your new query indeed you change the number of columns and they are not equal. For union its necessary to have the same number of columns
Its for this example :/ the threads has more information : Thread number one dateline: today Like number one dateline: yesterday 1:10pm Thread number two dateline: yesterday 1:09pm Like number two dateline: yesterday 1:08pm Like number three dateline: yesterday 1:07pm Thread number three dateline: yesterday 1:05pm
@JonathanNungaray If threads has more information and you really want to show it you still have to make sure that they have the same nr of colums. You could achieve this by simply adding something like this "" as username to assign empty values to virtual columns but if the data is that differnt i would not use a union because you have to do that for every column that threads has extra (and in the correct place)
|
0

The ORDER BY is only applied to the second query:

Select * From (
SELECT t.dateline, t.name, u.avatar
FROM ". TABLE_PREFIX ."threads t 
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)

UNION ALL

SELECT l.dateline, l.name, l.avatar
FROM ". TABLE_PREFIX ."likes l 
LEFT JOIN ".TABLE_PREFIX."treads t ON (t.uid=l.uid) ) allData

ORDER BY allData.dateline DESC 
LIMIT 10;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.