Reputation: 479
I have 2 tables both the table have exact same field names and datatype.
ISSUES: 1) I'm unable to receive data from both columns 2) I also need to count phone no in both table
The field names are member_id, name , phone
`SAMPLE DATA IN MEMBER TABLE`
------------------------------
member_id | name | phone |
------------------------------
100000 | ABC | 9876543210 |
-----------------------------*
`NOW SAMPLE DATA IN MEMBER_TEMP TABLE`
------------------------------
member_id | name | phone |
------------------------------
100001 | DEF | 9876543210 |
-----------------------------*
`NOW EXPECTED RESULTS/ OUTPUT EXPECTED`
------------------------------
member_id | name | phone |
------------------------------
100000 | ABC | 9876543210 |
------------------------------
100001 | DEF | 9876543210 |
-----------------------------*
BELOW IS LARAVEL QUERY BUILDER
$member_info = DB::table('member')->select('member_temp.*','member.*')->where(
array(
)
);
$member_info = $member_info->join('member_temp','member_temp.phone', '=', 'member.phone')
->get()->toArray();
//RAW MYSQL QUERY
select *
from `member`
inner join `member_temp`
on `member_temp`.`phone` = `member`.`phone`
THANKS IN ADVANCE
Upvotes: 0
Views: 88
Reputation: 408
I think you have started out with the wrong raw sql query.
It seems like you are looking for something more like this to get all the data you want out of the database:
select a.memberid as MemberId, b.memberid as MemberTempId, a.name as MemberName,
b.name as MemberTempName, a.phone from member as a join member_temp as b on
member.phone = member_temp.phone;
Upvotes: 1
Reputation: 827
I suggest you should use eloquent model to get phone column from both tables. it will always conflict in fluent query(join) because of same column name
Upvotes: 1