Tuskony Posted December 4, 2008 Share Posted December 4, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/135457-can-you-create-alias-columns-in-mysql/ Share on other sites More sharing options...
corbin Posted December 4, 2008 Share Posted December 4, 2008 SELECT col1 as some_alias FROM table; <name> AS <alias> Works in most types of queries/situations. Quote Link to comment https://forums.phpfreaks.com/topic/135457-can-you-create-alias-columns-in-mysql/#findComment-705699 Share on other sites More sharing options...
Tuskony Posted December 4, 2008 Author Share Posted December 4, 2008 Ok cool it does work. However how would I incorporate a where clause in there? A SQL query can't have 2 where clauses can it? I need to select the 2nd user name WHERE users.AccID = truck_image_comments.CommentBy Quote Link to comment https://forums.phpfreaks.com/topic/135457-can-you-create-alias-columns-in-mysql/#findComment-705709 Share on other sites More sharing options...
fenway Posted December 4, 2008 Share Posted December 4, 2008 You can use AND, OR in your WHERE clause. Quote Link to comment https://forums.phpfreaks.com/topic/135457-can-you-create-alias-columns-in-mysql/#findComment-706221 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.