0

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

8
  • Please include the raw MySQL query you want to use. Commented Aug 18, 2018 at 10:39
  • @Tim Biegeleisen please check i have updated my question Commented Aug 18, 2018 at 10:41
  • Is that the actual MySQL query you want to run? What about the counts? Commented Aug 18, 2018 at 10:45
  • @Tim Biegeleisen as mentioned i need to take result OR Count of matching phone number from both table. When i run the query i get only one result from a particular table Commented Aug 18, 2018 at 10:47
  • Please include sample data for both tables, along with the expected output. Commented Aug 18, 2018 at 10:48

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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;

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.