Jump to content

Can you create alias columns in mysql?


Tuskony

Recommended Posts

Hey guys,

 

I have 3 tables I am joining in a query. One is a table with user information, the other is a Report table, and one one is a comments table.

 

What I am doing is allowing users to report a comment or picture for abuse. So when I am on my admin page I want to see what comments have been reported and who they were reported by. I am also looking to display information about the comment etc.

 

Anyway my problem lies within my joins. I am already returning the UserName column of the person who reported the comment but I also want to return the UserName of the person who wrote the comment that reported.

 

Can I mod the following query to make this happen?

 

SELECT CRID, CID, ReportByAccID, Date, UserName, CommentBy, Comment, DateTime FROM CommentReports LEFT JOIN users ON CommentReports.ReportByAccID = users.AccID LEFT JOIN truck_image_comments ON CommentReports.CID = truck_image_comments.ComID ORDER BY CRID;

 

IE Can I do something like UserName2 = users.UserName where users.AccID = truck_image_comments.CommentBy;

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/135457-can-you-create-alias-columns-in-mysql/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.